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

Closed
doctrinebot opened this Issue Apr 5, 2012 · 7 comments

2 participants

@doctrinebot

Jira issue originally created by user nlaplante:

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

HistoryItem:
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 p.photo LEFT JOIN c.comment

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

SELECT h0.id AS id0, h0_.createdAt AS createdAt1, h1_.id 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 = p2_.id INNER JOIN Comment c3_ ON h1_.comment_id = c3_.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

@doctrinebot

Comment created by nlaplante:

Fix entity names

@doctrinebot

Comment created by @FabioBatSilva:

Hi Nicolas

Could you attach your entities please ?

@doctrinebot

Comment created by nlaplante:

Sure, here are the 3 entities

@doctrinebot

Comment created by nlaplante:

Here are the referenced entities in case you need them too

@doctrinebot

Comment created by @beberlei:

Fixed

@doctrinebot

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added this to the 2.1.7 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment