Ar Relation

Good day guys I have here 4 database table request, refill, dosage, medicine

with AR relations as follows.

refill table has

'rflRqst' => array(self::BELONGS_TO, 'ShisRequest', 'rfl_rqst_id'),

request table has

'rqstDtl' => array(self::BELONGS_TO, 'ShisMeddetails', 'rqst_dtl_id'),

dosage table has

'dtlMed' => array(self::BELONGS_TO, 'ShisMedinventory', 'dtl_med_id'),

so it should look like this relation

refill->request->dosage->medicine name table.

and has a CGridView with column of


but when I tried to create a search statement in the model it gives me error.

public $med_search;

$criteria->with = array('rflRqst.rqstDtl.dtlMed');

$criteria->compare('rflRqst.rqstDtl.dtlMed.med_name', $this->med_search, true);

Can you please help me how to fix this. tnx in advance.

you are doing wrong. why are you accessing your relation like this

$criteria->with = array('rflRqst.rqstDtl.dtlMed');

instead of

$criteria->with = array('rflRqst');

if you want to join all the relations to your primary table then use this

$criteria->with = array('rflRqst','rqstDtl','dtlMed');

and to compare with relation then use anyone of the following snippet

$criteria->compare('rflRqstmed_name', $this->med_search, true);


$criteria->compare('dtlMed.med_name', $this->med_search, true);


$criteria->compare('rflRqst.med_name', $this->med_search, true);

tnx Ahamed ill try this :)

I forgot to mention that the relation i listed above are in different model I Edited the post please check it again thank you.

first of all you did not specified in which model you are currenlty using GridView and why are you chaining your relations too much?

iam using my cgridview in refill model, I guess to normalize the database table :)