Yii Framework Forum: Not Getting All Records In Cactivedataprovider With Relation - Yii Framework Forum

Jump to content

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

Not Getting All Records In Cactivedataprovider With Relation

#1 User is offline   nik silicon 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 03-October 12

  Posted 03 October 2012 - 08:08 AM

Hello Friends,

Relation with state table.
return array(
'relState'=>array(self::HAS_ONE,'State','state_id'),
);

$Data Container for contact detail with state table relation.

$DataProvider = new CActiveDataProvider ('Contact', array(
'criteria' => array (
'with' => array ('relState')
) ,
'pagination' => array('PageSize' => 20, )
));
return $DataProvider;

I am using above code and i am getting correct output. The only thing is that i am getting all records of contact table not from state.
I am having state field in contact table and it is storing state id as foreign key while state table has state_id as primary key. I want to replace state id with state name in all records. But when i am using CActiveDataProvider, i can not achieve this and getting only records of contact table.

So Please help me if anybody has solved this issue.
Thanks in advance...
0

#2 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 665
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 03 October 2012 - 09:55 AM

It seems you have many questions and I was a bit confused.
Please separarate your issues so we can try to help you better.

Regarding your question about returning many States for a Contact (if I understood it correctly), you have a HAS_ONE relation between those models. This means that there's only one State for each Contact.

You may want to check the guide about relational AR and review your schema.
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