开发者

cakephp throws error while deleting from self referencing table

I have a table with non-unique key referencing primary key. When I delete records by using the same non-unique column in where clause, cakephp joins the same table with same alias that causing SQL error.

$this->MyModel->deleteAll(array('non_uniq_id'=>array_keys($data)));

I get MySQL error as follows:

SQL Error: 1066: Not unique table/alias:...

I tried lo开发者_如何转开发ng time to fix it with cakephp's ORM (I can avoid it with my own SQL queries). I also tried this solution, but it doesn't help.

Any help is appreciated.


Since you'll probably have this problem often, you should make sure your associations and models all have unique names.

Failing that, you can unbind the troubling association temporarily, which should cause it not to be joined:

$this->MyModel->unbindModel(array('hasMany' => array('MyModel')));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜