简体   繁体   English

使用symfony的简单原则查询

[英]Simple doctrine query using symfony

I'm trying to build a basic query using symfony and doctrine. 我正在尝试使用symfony和主义建立一个基本的查询。 The query will return a User and all the jobs they are working on. 该查询将返回用户及其正在处理的所有作业。 From the two tables 'User' and UserDetails (Contains User_id and Job_id). 从两个表“用户”和UserDetails(包含User_id和Job_id)。 User is mapped to userdetails correctly as one- many. 用户正确地映射到多个用户详细信息。

my query is 我的查询是

SELECT   userdetails, u FROM TestBundle:User 
join userdetails.u

As user is a field in userdetails, but userdetails isn't a member of users the following query doesn't work. 由于user是userdetails中的一个字段,但userdetails不是用户的成员,因此以下查询不起作用。 Is there any way to write this so the result will look like User.userDetails. 有什么办法可以编写此代码,因此结果将类似于User.userDetails。

Try something like 尝试类似

SELECT
  u, ud
FROM 
  TestBundle:User u
JOIN //LEFT JOIN if you want also users without UserDetails
  TestBundle:UserDetails ud
WITH
  u.id = ud.user_id

of course your variables (like ud.user_id ) could vary but we don't have enough informations to work on so we have to guess 当然,您的变量(例如ud.user_id )可能会有所不同,但是我们没有足够的信息来处理,因此我们不得不猜测

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM