Skip to content


DDC-1239: Using a repository with composite keys generates invalid SQL #1848

doctrinebot opened this Issue · 3 comments

2 participants


Jira issue originally created by user spiffyjr:

Invalid SQL is generated when using composite keys along with Repository methods (fineOneBy, etc). Everything works properly when using createQuery() to generate DQL manually.

$q = $this->_em
"SELECT c,c2,g FROM Entity\OAuth\Consumer c LEFT JOIN g LEFT JOIN c2 WHERE c.key = '{$consumer_key}'");
$this->_consumer = $q->getSingleResult();

$this->consumer = $this->em->getRepository('Entity\OAuth\Consumer')
->findOneBy(array('key' => $consumer_key));

Generated SQL for "invalid" method:
SELECT ... FROM oauth_consumer t0 LEFT JOIN groop t10 ON t0.groupId = LEFT JOIN company t17 ON t0.companyId = LEFT JOIN clinic t28 ON t0.dsid = t28.dsid t0.rid = t28.rid LEFT JOIN user t50 ON t0.userId = WHERE t0.key = ?

Notice the missing AND in the query above. I've attached the entities in question.


Comment created by @beberlei:



Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.1 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.