如何在doctrine1.2中使用innerJoin?
我有一些代码(有效):
$q = Doctrine_Query::create()
->from('UsersProjects up')
->innerJoin('up.Users u');
两个问题:
有人可以给我举一个例子,如何加入下一张表(多个表)? Doctrine 的文档仅包含基本示例... :-(
可以我将
innerJoin()
与我的数据库中的任何表(例如与用户相关的用户类型)或仅与与 UsersProjects 相关的表(在本例中:项目和用户)一起使用?我收到错误“未知关系”。
I have some code (works):
$q = Doctrine_Query::create()
->from('UsersProjects up')
->innerJoin('up.Users u');
Two questions:
Could sombody show me an example, how to join next table (more then one)? Doctrine's documentation contains only basic examples... :-(
Can I use
innerJoin()
with any table from my db (eg. Usertypes related with Users) or only with table related with UsersProjects (in this case: Projects and Users)? When I trying to do it then I get error "Unknown relation".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Doctrine 查询使用“流畅”接口,这意味着每个方法都会返回对查询的引用,以便您可以继续链接新方法(select()、innerJoin()、from()、where() 等)。您可以根据需要添加任意数量的innerJoins,但连接的对象/表需要与您已连接的对象/表之一相关(或表中的基础)。例如:
如果不进入原则提供的RawSql接口,就无法连接不相关的表。您可以看到只有 Users 与基表 UsersProjects 相关。电话号码和地址与用户相关,城市与地址相关。
Doctrine queries use a "fluent" interface, which means each method returns a reference to the query, so that you can keep chaining new methods (select(), innerJoin(), from(), where(), etc). You can add as many innerJoins as you want, but the joined object/table needs to be related to one of the ones you have already joined (or the base from table). For example:
You can't join unrelated tables without getting into the RawSql interface that doctrine provides. You can see that only Users relates to the base table UsersProjects. PhoneNumbers and Addresses relate to a User and City relates to an Address.