Skip to content Skip to sidebar Skip to footer

How To Translate This Sql Query To Dql?

I have a lot of difficulties in trying to translate this SQL query to a DQL one (I am using Symfony2). SELECT d.* FROM Document d JOIN DocumentType dt ON dt.id = d.document

Solution 1:

  • Instead of database fields, you need to use the fields of you Document and DocumentType classes.

  • The join is done by naming the association field of your document (something like d.documenttype)

  • For those MySQL date functions: At least as far as I know, you would need to write custom DQL functions. Behind that link there is an example of an INTERVAL function. This might be the point where you want to execute the native SQL query instead.

SELECT d 
FROM MyProject\Model\Document d
    JOIN d.documenttype
WHERE [...your own DQL functions here...]

Post a Comment for "How To Translate This Sql Query To Dql?"