php - Yii CActiveDataProvider with() and join -


i want have separate row each related object in cgridview.

modelb has modelaid, has_many relationship.

the following query returns trying get:

select * modela join modelb b on b.modelaid = a.id 

here getting separate rows each corresponding modelb row, records modela may duplicated.

however, following provider not returning expected records, how can make use of in cactivedataprovider

$provider = new cactivedataprovider ("modela", array ("criteria" => array (             "with" => array("modelb")             )         )); 

if add join "join" => " join modelb b on b.modelaid = t.id", , remove with() giving correct records, when include with() gives modela records.

what correct way of getting data modela including separate rows modelb relation?

you can use cdbcriteria in ultimate easy fashion

$criteria=new cdbcriteria(); $criteria->with=array('tomodelb'); //here tomodelb defined relation in modela modelb $dataprovider=new cactivedataprovider('modela',array('criteria'=>$criteria)); 

but before make sure have proper relations defined these 2 models.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -