我正在尝试使用 orWhere 子句中的子查询(使用 Doctrine)进行简单查询。
一如既往,Doctrine 尝试重命名每个别名并完全破坏查询......
这是一个例子:
$q = Doctrine_Query::create()
->from('Actualite a')
->where('a.categorie_id =?', $id)
->orWhere('a.categorie_id IN (select id from cat.categorie as cat where cat.categorie_id =?)', $id)
->execute();
在 MySQL 中会生成如下内容:
SELECT *
FROM actualite a
WHERE a.categorie_id = 1 OR a.categorie_id IN (SELECT cat.id FROM categorie cat WHERE cat.categorie_id = 1);
关于它的一切都是正确的,但是 Doctrine 再次摧毁了它: 找不到类猫
每次我尝试用 Doctrine 做一些有点复杂的事情时,我都会遇到别名错误。有关如何解决此问题的任何建议或想法?
谢谢!
最佳答案
您提供的 SQL 示例很好,但相应的 Doctrine 语法有几个错误。这是一个干净的版本:
$q = Doctrine_Query::create()
->select('a.*')
->from('Actualite a')
->where('a.categorie_id = ?', $id)
->orWhere('a.categorie_id IN (SELECT cat.id FROM Categorie cat WHERE cat.categorie_id = ?)', $id)
->execute();
关于php - 使用带有别名的 Doctrine/错误的子查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4326108/