Skip to content


DDC-1770: Select from multiple subclassed entities generates SQL syntax error #2422

doctrinebot opened this Issue · 7 comments

2 participants


Jira issue originally created by user nlaplante:

I have 2 entities subclassing a "master" entity using single table inheritance:

createdAt datetime

PhotoHistoryItem extends HistoryItem
photo: (foreign key to Photo entity)

CommentHistoryItem extends HistoryItem
comment: (foreign key to Comment entity)

I want to select all of them using the following DQL:

SELECT p, c FROM ProFolioBundle:PhotoHistoryItem p, ProFolioBundle:CommentHistoryItem c LEFT JOIN LEFT JOIN c.comment

But the generated SQL has an error in the final AND syntax (it generates "AND AND"):

SELECT AS id0, h0_.createdAt AS createdAt1, AS id2, h1_.createdAt AS createdAt3, h0_.type AS type4, h1_.type AS type5 FROM HistoryItem h0_, HistoryItem h1_ LEFT JOIN Photo p2_ ON h0_.photo_id = INNER JOIN Comment c3_ ON h1_.comment_id = WHERE (h0_.type IN ('photo') AND AND h1.type IN ('comment')) LIMIT 20

The error MySQL throws is:

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 'AND h1_.type IN ('comment')) LIMIT 20' at line 1


Comment created by nlaplante:

Fix entity names


Comment created by @FabioBatSilva:

Hi Nicolas

Could you attach your entities please ?


Comment created by nlaplante:

Sure, here are the 3 entities


Comment created by nlaplante:

Here are the referenced entities in case you need them too


Comment created by @beberlei:



Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.1.7 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.