Yii Framework Forum: Access Model Attribute With Two Relation. - Yii Framework Forum

Jump to content

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

Access Model Attribute With Two Relation. Rate Topic: -----

#1 User is offline   Y!! 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 09-February 13

Posted 27 March 2013 - 11:50 PM

I have a problem while sorting model attribute that we are displaying with two relations.
$sort = new CSort;

$sort->attributes = array(
'c_name'=>array(
'asc' => 'client.name',
'desc' => 'client.name DESC'
),
),'*',
);

return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'sort'=>$sort,
));

this works fine it has only one relation client.

but when i have two relation,
'project_name'=>array(
'asc' => 'Subscription.project.p_name',
'desc' => 'Subscription.project.p_name DESC'
),'*',

where Subscription and project are relations.How can i do this one??
0

#2 User is offline   hiral darji 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 31-May 12
  • Location:Ahmedabad

Posted 28 March 2013 - 05:16 AM

View PostY!!, on 27 March 2013 - 11:50 PM, said:

I have a problem while sorting model attribute that we are displaying with two relations.
$sort = new CSort;

$sort->attributes = array(
'c_name'=>array(
'asc' => 'client.name',
'desc' => 'client.name DESC'
),
),'*',
);

return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'sort'=>$sort,
));

this works fine it has only one relation client.

but when i have two relation,
'project_name'=>array(
'asc' => 'Subscription.project.p_name',
'desc' => 'Subscription.project.p_name DESC'
),'*',

where Subscription and project are relations.How can i do this one??


Here i have one model StudentTransaction in it this code is define, and i want to get cityname throught it in desc order.

here in this model Rel_Student_Address(relation) is define which refer to StudentAddress Model

then in my StudentAddress Model Rel_c_city(relation) is defines which refer City Model

may this following code which is work for me can help you to solve your problem

$stud_data = new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
			'sort'=>array(
			'attributes'=>array(
           		        'student_transaction_student_address_id'=>array(    
              		        'desc'=>'Rel_Student_Address.Rel_c_city.city_name DESC',
			       ),
           		 ),
		      ),
		));



0

#3 User is offline   le_top 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 420
  • Joined: 08-June 10
  • Location:France (Ile-de-France/Val d'Oise)

Posted 29 March 2013 - 03:59 PM

http://www.yiiframew...searchbehavior/ !!!
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