在没有指定关系的表上加入Doctrine中的查询 [英] Join queries in Doctrine on tables without specified relations
问题描述
但是,表1有一个外键引用表2的主键。显然,我没有设计好数据库,但现在是缓解时间。
我必须在两个表之间做一个左连接,再加上一个where子句,它将检索我想要的选择行。为此,我做:
Doctrine_Query :: create() - > select('t。*,l。 ('t.Cid c') - > leftJoin('c.Lesson l') - > where('t.section =?' 批判性阅读);
这通常应该这样做,但是它不是因为它返回的是分类表中的所有行不管在哪里的条件。我在想,这是因为列中没有指定关系吗?这是可笑的,因为查询工作,只有在一个教义的上下文它不是。
谢谢
在原则中,您只能使用您在模式中定义的关系来加入,这是一个知道的限制。您可以使用 Native SQL 功能作为解决方法。
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
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.
这篇关于在没有指定关系的表上加入Doctrine中的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!