Questions tagged [dql]

Doctrine Query Language (DQL) is an Object Query Language created for helping users in complex object retrieval.

Summary

DQL stands for Doctrine Query Language and is an Object Query Language derivate that is very similar to the Hibernate Query Language (HQL) or the Java Persistence Query Language (JPQL).

In essence, DQL provides powerful querying capabilities over your object model. Imagine all your objects lying around in some storage (like an object database). When writing DQL queries, think about querying that storage to pick a certain subset of your objects.

Questions

  • How to write DQL statements to achieve a particular SQL statement?
  • Why will a DQL statement not work as expected?

More Information

To learn more about DQL visit

Doctrine 1.2
http://www.doctrine-project.org/projects/orm/1.2/docs/manual/dql-doctrine-query-language/en#dql-doctrine-query-language

Doctrine 2.0
http://www.doctrine-project.org/docs/orm/2.0/en/reference/dql-doctrine-query-language.html

1296 questions
15
votes
2 answers

Better to use DQL for getting Column Count or Get Collection Then Count?

I am quite sure that DQL will be the way to go, but I am wondering if Doctrine, i am using Doctrine 2, has someway to return the row count. I won't be using the rows itself, I just want the count.
Jiew Meng
  • 84,767
  • 185
  • 495
  • 805
14
votes
2 answers

Doctrine: Multiple (whereIn OR whereIn) query?

I'm having trouble crafting a fairly simple query with Doctrine... I have two arrays ($countries, $cities) and I need to check whether database record values would match any inside either. I'm looking for something like: ->whereIn('country', 'city',…
Tom
  • 30,090
  • 27
  • 90
  • 124
14
votes
1 answer

doctrine2 dql member of on collection subentities

Using dql I tried to check if a entity is member of a collections subentity entites: product customer customer.orders (collection) customer.orders.products (collection, type: product) …
Martin Abraham
  • 752
  • 7
  • 24
14
votes
3 answers

Select One column Doctrine DQL

I need a simple column for a table. By example a table "project", with column id, name and year. If I do: $q = Doctrine_Query::create() ->select('a.pro_id') ->from('fndr_proyecto a') ->where('a.pro_id =?',1); $pro =…
h3g0r_
  • 219
  • 1
  • 4
  • 15
14
votes
3 answers

Using JOIN in Symfony2/Doctrine SQL

I have a problem while trying to USE QueryBuilder OR DQL. I have the following relation: User <-1:n-> Profile <-n:m-> RouteGroup <-1:n-> Route I would like to make a DQL that lists all the routes that a specific user has access. I can get this…
Marcelo Diotto
  • 443
  • 1
  • 3
  • 10
14
votes
1 answer

Use a DATE() function in a WHERE clause with DQL

I get a strange error when I execute this DQL query: SELECT u FROM User u LEFT JOIN u.schedule s WHERE DATE(s.timestamp) = DATE(NOW()) The exception is thrown by Doctrine with the message: Expected known function, got 'DATE' The problem looks…
Jurian Sluiman
  • 13,498
  • 3
  • 67
  • 99
14
votes
1 answer

What is the difference between JOIN ON and JOIN WITH in Doctrine2?

What is the difference between JOIN ON and JOIN WITH in Doctrine2? I couldn't find any relevant info in the manual.
Trent
  • 5,785
  • 6
  • 32
  • 43
13
votes
4 answers

Doctrine DQL Date as parameter problem

Hi there I got a DQL that works (I get all my event since the beginning) : DoctrineHelper::getEntityManager()->createQueryBuilder() ->select("u.surname, count(u.surname) as total") ->from("User", "u") ->from("AbstractEvent", "e") …
Michael Laffargue
  • 10,116
  • 6
  • 42
  • 76
13
votes
2 answers

When would it be worth it to maintain an inverse relationship in Doctrine2?

In the Doctrine manual, under Constrain relationships as much as possible, it gives the advice "Eliminate nonessential associations" and "avoid bidirectional associations if possible". I don't understand what criteria would make an association…
theazureshadow
  • 9,499
  • 5
  • 33
  • 48
12
votes
1 answer

Doctrine won't let me select specific fields

The symfony framework features an app/console file that can be executed via php to perform some maintenance tasks. It allows users to run DQL queries as well: # php app/console doctrine:query:dql --hydrate=array \ 'SELECT u.id, u.nameFirst,…
12
votes
3 answers

Get random records with Doctrine

I wonder how to get a random number of Members from a Group, but I do not know what is the best way to do this, and I think ORDER BY RAND() is not the best alternative, as a Group can have more than 100,000 Members, performing this type of query…
jonathancardoso
  • 11,737
  • 7
  • 53
  • 72
12
votes
2 answers

Doctrine 2 DQL CASE WHEN in Count

I have this Query in native MySQL Code SELECT * FROM `turn` LEFT JOIN ( poi ) ON ( turn.id = poi.turn_id ) GROUP BY turn.id ORDER BY count( case when poi.image = 1 then 1 else null end) DESC; I need to rebuild this in Doctrine 2 DQL My attempt…
KhorneHoly
  • 4,666
  • 6
  • 43
  • 75
11
votes
1 answer

dql query error class is not defined

Trying to conver my sql queries into dql, seems im doing something wrong. I need basic joins, something like this. SELECT a.id, a.title, u.name FROM articles JOIN users ON a.author_id = u.id Tried SELECT a.id, a.title, u.name FROM Article a JOIN…
Tigran Muradyan
  • 402
  • 1
  • 8
  • 24
11
votes
2 answers

Doctrine: Select statement using equals not accepted

According to DDC-2204 issue which states [Order by With Equals] is supported by including the condition in the SELECT clause, aliasing it, then using it. You might need to use "AS HIDDEN name" to prevent it from appearing in the result following…
Olia.Bn
  • 190
  • 9
11
votes
9 answers

How can get unique values from data table using dql?

I am having a table in which there is a column in which various values are stored.i want to retrieve unique values from that table using dql. Doctrine_Query::create() ->select('rec.school') …
Mohit Jain
  • 43,139
  • 57
  • 169
  • 274
1 2
3
86 87