Trouble With Multi Level Foreign Key Search

Hi,

I have a chain like multi level relations for foreign keys:

model MyModel:

public function relations()

{


	// NOTE: you may need to adjust the relation name and the related


	// class name for the relations automatically generated below.


	return array(


		'merchantIdFk' => array(self::BELONGS_TO, 'Merchant', 'merchant_id_fk')


     }

I have the following chain like dependency for foreign keys:

‘merchantIdFk->contactIdFk->addressIdFk->zipCodeIdFk’

This errors as myModel does not have have zipCodeIdFK:

$criteria->with=array(‘merchantIdFk->contactIdFk->addressIdFk->zipCodeIdFk’);

How do I make MyModel searchable by Zipcodes?

-Thanks

VG

Hi Gaur, welcome to the forum.




$criteria->with=array(

    'merchantIdFk',

    'merchantIdFk.contactIdFk',

    'merchantIdFk.contactIdFk.addressIdFk',

    'merchantIdFk.contactIdFk.addressIdFk.zipCodeIdFk',

);

$criteria->compare('addressIdFk.city_name', $cityNameToSearch);

$criteria->compare('zipCodeIdFk.zip_code', $zipCodeToSearch);