Intro
I'm following this guide here and I'm stuck on the very last part: http://symfony.com/doc/2.0/cookbook/security/entity_provider.html
I'm trying to query from the account table and join the group table as well. It's a many to many relationship with an intermediate table account_group.
account Table Fields: id, firstName, and email
account_group Table Fields: account_id and group_id
group Table Fields: id, name, and role
Problem
Here is my DQL:
SELECT a.firstName, g.role
FROM WikiRosterMainBundle:Account a
LEFT JOIN a.groups g
WHERE a.email = :email
I'm getting an internal server error:
An exception occurred while executing 'SELECT a0_.id AS id0, a0_.firstName AS firstName1, a0_.email AS email3, g1_.role AS role18 FROM account a0_ LEFT JOIN account_group a2_ ON a0_.id = a2_.account_id LEFT JOIN group g1_ ON g1_.id = a2_.group_id WHERE a0_.email = ?' with params {"1":"[email protected]"}:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group g1_ ON g1_.id = a2_.group_id WHERE a0_.email = '[email protected]'' at line 1
What I've tried:
+Adding a primary key to the account_group table (didn't work)
+Writing my own left join mysql query and inputing it in phpmyadmin (works with a single left join, but fails when I attempt to join 3 tables)
+Flipping the table I'm joining / selecting from
Research I've done
It seems like left join changed in mysql 5. I've looked at documentation and other stack overflow questions:
http://dev.mysql.com/doc/refman/5.0/en/join.html
MySQL LEFT JOIN after 5.0.12 changes - How to rewrite query
Thanks for any help!