Not Getting All Records In Cactivedataprovider With Relation


(Nik1212ruby) #1

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…


(Yii) #2

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.