user3248331
user3248331

Reputation: 105

Simple doctrine query using symfony

I'm trying to build a basic query using symfony and doctrine. 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). 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. Is there any way to write this so the result will look like User.userDetails.

Upvotes: 0

Views: 70

Answers (1)

DonCallisto
DonCallisto

Reputation: 29932

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

Upvotes: 1

Related Questions