Yii Framework Forum: Ordering Cactivedataprovider From Second Join - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Ordering Cactivedataprovider From Second Join Rate Topic: -----

#1 User is offline   Jonny 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 184
  • Joined: 26-December 11

Posted 13 April 2013 - 11:25 AM

Hi

I have the following code:

	public function actionIndex($id) 
	{
		
		$dataProvider=new CActiveDataProvider('Item', array(
			'criteria' => array(
			'with' =>'Area',
			'condition' => 't.Area_id=:id',
			'params' => array(':id'=>$id),


What I need to do is join another table of featured Items and then order the whole thing with by what results are featured?

So far I got to this:

	public function actionIndex($id) 
	{
		
		$dataProvider=new CActiveDataProvider('Item', array(
			'criteria' => array(
			'with' =>'Area',
			'condition' => 't.Area_id=:id',
			'params' => array(':id'=>$id),
                        'with' =>'featuredItems',




But then I just keep inuring errors if I try to order the results. I'm not sure how to use the Item.id to join the featuredItems.item_id as a condition? Or if that column data would even be available during this point in the query
0

#2 User is offline   le_top 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 332
  • Joined: 08-June 10
  • Location:France

Posted 13 April 2013 - 11:35 AM

Use my RelatedSearchBehavior extension. It's intended to be used in a 'search()' function but it does return a DataProvider'.

To respond to your question: the join is to be specified in the relations of the model class, where 'with' references this relation. This implies that the CCommandBuilder will include the relation in the query. As the relation is then included in the query, you can reference it in the sort.
0

#3 User is offline   Jonny 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 184
  • Joined: 26-December 11

Posted 13 April 2013 - 11:42 AM

Ah ok tahnk you.

I managed to get the join across ok, it was the params and condition I had trouble with.

Will look at the behaviours extension too.

Thanks very much
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users