0

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.

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the help, had to change ON to WITH to get it to work. It still put userdetails as a seperate row, but does what i need. Cheers
@user3248331: yes, I was into "autopilot" mode and wrote with a typo; updated. Dont' forget to accept the answer if this works for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.