Search on related table

I have the following relation in model file:


'	public function relations()

	{

		.....

	'railways' => array(self::BELONGS_TO, 'Railways', 'railway'),

	..			}

The table railways has a column ‘zone’.

I now modify the model search functiion thus.


	public function search()

	{

		.....


		$criteria->compare('railways.zone',$this->railway);


	..			}

When I run the application I get the ‘Column not found error’ on railways.zone.

Where am I making the mistake? Thanks.

Hello,

try this

$model=myModel::model()->search()->with(‘railways’);

this should work.


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

@Thanks mbi. Missed it!! Now works.




        .......


 $criteria->with = array('railways','equipments'...);




...

for more than one related table.

So you have a main table and Railways table with "zone" field. If you wanted to add "zone" field in the Advanced Search form (admin.php) of the main table, how would you accomplish?