How to define column in search condition

I have code to search across multiple tables, they have columns with the same name, but when I use the following line:

entity::model()->with(‘metadata’,‘entityType’)->findAll(array(‘condition’=>‘entityType.typeId=3’))

error reported: CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘entityType.typeId’ in ‘where clause’

Anyone knows how to do search with conditions like entityType.typeId=3? or how to make it recognize the typeId of entityType?

Thanks!

Unknown column error ?

Review you configuration at model and take a look at how to use condition in Criteria :)

When you talk about PKs you could take a look at : http://www.yiiframework.com/doc/api/CActiveRecord#safeAttributes

You should add an alias in with(). So instead of:

you should use something like:




entity::model()

  ->with(array(

    'metadata',

    'entityType' => array('alias' => 'entityType'),

  ))

  ->findAll(array('condition'=>'entityType.typeId=3'))



This is because if you don’t define an alias for the relation Yii will assign one automatically(e.g. “t0”).