rroasio
(Riccardo Roasio)
1
Hi,
i have two models with a BELONGS_TO relation.
both have a name column.
now if i do something like this:
$activities_c=new CDbCriteria;
$activities_c->with=array(
'macroarea_er',
);
$activities_c->order='name ASC';
it gives me an error saying that name column is ambiguous.
This is correct…the question is…how can i specify which name column it has to use?
Thansk,
Riccardo
Add the table name before the column name, e.g.
$activities_c=new CDbCriteria;
$activities_c->with=array(
'macroarea_er',
);
$activities_c->order='macroarea_er.name ASC';
rroasio
(Riccardo Roasio)
3
The other table is called activities, but if i do like this:
$activities_c->order='activities.name ASC';
it gives me this error:
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘activity.name’ in ‘order clause’
while if i do like you suggest:
$activities_c->order=‘macroarea_er.name ASC’;
it works but i nedd the first one to work…
Riccardo
jayrulez
(Waprave)
4
use t.name for the main table
rroasio
(Riccardo Roasio)
5
Ok, now it works.
But there is a "rule" to know which t to use?
Because in the query yii use t ,t0 ,t1 and so one…correct?