September 9, 2011, 1:37am
If "with" is used by "criteria", pk of relation will have been automatically added to the "order by" phrase. And it has caused the ambiguous error.
How can it avoid inserting "id"?
I would like to search table"log_matter" by using "$matterid" as a key,
and to acquire data order by "dtUpd". And I would like to acquire "strName" from Chargers.
Specifically, they are the following contents.
[indent] id (pk)
[indent] id (pk)
public function relations()
'charger'=>array(self::BELONGS_TO, 'Chargers', 'iChargerId'),
public function loadLogs($matterid)
$model = new LogMatter;
$rows = $model->model()->findAll($criteria);
Integrity constraint violation: 1052 Column ‘id’ in order clause is ambiguous. The SQL statement executed was: SELECT
t LEFT OUTER JOIN
charger ON (
id) WHERE (iMatterid=:iMatterid) ORDER BY t.dtUpd, id
I am looking forward to your reply.
September 9, 2011, 6:36am
It is weird. Never happened with me before although I used similar things numerous times in the past. The only difference in my code is I used to set $criteria->together = true as well.
September 9, 2011, 8:33am
Although I added this, the same error occurred.
I gave up using relation and used "left outer join".
$criteria->join='LEFT OUTER JOIN `chargers` `charger` ON (`t`.`iChargerId`=`charger`.`id`)' ;
However, I am very unwilling.
Aren’t there those who know the cause?
September 9, 2011, 10:41am
Unfortunately the yii community is not too big and the ones who knows the framework inside-out I assume are working on the code. So help is not coming everytime but if you dig in the code you can figure out why it is happening for you.
September 9, 2011, 2:19pm
Try out with adding below to order
I too experienced same error when having same column name in both tables.Then we have to specify which table.
September 10, 2011, 5:54pm
This time, I could not but give up on account of time. However, I wish to be helpful to other users. I will investigate from now on as perfectly as possible.
September 10, 2011, 6:06pm
I had already tried this. ‘id’ has still been added. It may be necessary to investigate this problem deeply so that Greg may say.