Reputation: 4491
I have thoroughly scoured SO and Google however I can't find an answer to this very basic question.
I have the following entities in Symfony2
ADR\PortalBundle\Account
ADR\UserBundle\User (FOSUserBundle)
Each user has one account, and one account can have many users (all which seems to work fine elsewhere on the site).
I have the following query:
$query = $em->createQuery(
'SELECT u, a
FROM ADRUserBundle:User u
JOIN ADRPortalBundle:Account a
WHERE u.id = :userId'
)->setParameter('userId', $this->getUser()->getId());
This returns me the single account data, as well as all accounts.
What I actually want is the account data for this particular user.
Having reversed the query so FROM
is the account entity and JOIN
is the user entity I get the reverse, a single account and all users in the database.
Upvotes: 0
Views: 69
Reputation: 3698
This probably happens because you are not actually joining tables on a specific field.
So you would need something like (I'm using u.account as the user property that references the account)
JOIN ADRPortalBundle:Account u.account a
You might also want to take a look at: http://docs.doctrine-project.org/en/2.1/reference/dql-doctrine-query-language.html.
Upvotes: 1