Join queries in Doctrine on tables without specified relations

跟風遠走 提交于 2019-12-11 10:27:12

问题


I have two tables that do not have a relation defined with each other in the schema.yml. However, table 1 has a foreign key reference to the primary key of table 2. Clearly, I goofed up by not designing the database well, but now it's mitigation time.

I must do a left join between the two tables coupled with a where clause that will retrieve the select rows I want. And to do this, I do:

 Doctrine_Query::create()->select('t.*, l.lid')->from('Taxonomy t')->leftJoin('t.Cid c')      ->leftJoin('c.Lesson l')->where('t.section = ?','Critical reading');

This should typically do it, but it does not because what it returns is all the rows from taxonomy table irrespective of the where condition. I am thinking, is this because of the relation not being specified in the column? That would be ridiculous cause the query works, only in a doctrine context it does not.

Thanks


回答1:


In doctrine you can only join using the relations you defined on your schema, this is a know limitation. You may use the Native SQL feature as a workaround.



来源:https://stackoverflow.com/questions/11680606/join-queries-in-doctrine-on-tables-without-specified-relations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!