Problem with same column name with two tables

Hi there,

I am having one issue while fetching details from related tables.

I have two tables having column named as user.

So while fetching details from first table,I have

$criteria->with = array(‘table2’ => array(

                                           'select' => array(


                                                             'user','date'


                                                             )


                                           ),                               


                            );

and to check the user column from first table itself I have:

$criteria->compare(‘user’, ‘Active’,true);

Now, this gives me an error for column ambiguity. I tried adding modelname to compare criteria as:

$criteria->compare(‘FirstModel.user’, ‘Active’,true);,

but it didn’t solve the issue.

Any help is appreciated.

Thanks in advance.

Try adding the prefix ‘t.’ to the column name. Where ‘t’ refers to your current model.


$criteria->compare('t.user','Active', true);

Cheers,

Matt

also you can get table alias




$alias = $this->getTableAlias(true);

$criteria->compare($alias . '.`user`','Active', true);