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
8
votes
1 answer

Using COLLATE inside Doctrine DQL Query (Symfony2)

I can't find anything related to using COLLATE in a DQL query with Doctrine (and ofcourse it doesn't seem to work). My specific problem: I have a table with utf8_general_ci charset. I have one specific field in it which has accented characters (like…
hattila
  • 490
  • 5
  • 13
8
votes
1 answer

Leave out discriminator part of Doctrine' generated SQL

Assume the following AbstractPage model: /* * @ORM\Entity * @ORM\Table(name="page") * @ORM\InheritanceType("SINGLE_TABLE") * @ORM\DiscriminatorColumn(name="type", type="string") * @ORM\DiscriminatorMap * ({ * …
Roel van Duijnhoven
  • 800
  • 1
  • 7
  • 24
8
votes
1 answer

Doctrine DQL: how to get expression to inversed side

I wish to fetch an entity where the inversed association does not exist (on a 1:1 association) I get the error: A single-valued association path expression to an inverse side is not supported in DQL queries. Use an explicit join…
Tjorriemorrie
  • 16,818
  • 20
  • 89
  • 131
7
votes
3 answers

Doctrine 2 JOIN ON error

I try to execute this query in my CompanyRepository $qb = $this->_em->createQueryBuilder(); $qb->select(array('c', 'ld')) ->from('Model\Entity\Company', 'c') ->leftJoin('c.legaldetails', 'ld', \Doctrine\ORM\Query\Expr\Join::ON,…
Russian Raccoon
  • 127
  • 1
  • 1
  • 9
7
votes
1 answer

DQL query with joining table and two join

I have 2 entity: /** * @ORM\Entity * @ORM\Table(name="users") */ class User { /** * @ORM\ManyToMany(targetEntity="Myapp\UserBundle\Entity\Group") * @ORM\JoinTable(name="user_groups", * …
user1063963
  • 1,355
  • 6
  • 22
  • 34
7
votes
1 answer

Doctrine 1.2 how to compare dates

How can i set a condition, in a where clause of Doctrine 1.2 ORM to specify Greater than date in DQL example Doctrine_Query::create() ->from('user u') ->where(?) ->execute(); Thanks
Juan Jo
  • 882
  • 2
  • 8
  • 17
7
votes
2 answers

How to make an insert query in DQL

I'm working with symfony and I would like to know how I can do a simple insert using the doctrine:dql task. ./symfony doctrine:dql ""
greg0ire
  • 22,714
  • 16
  • 72
  • 101
7
votes
2 answers

Doctrine - how to check if a collection contains an entity

I have two entities User and Article with many-to-many relation as Article can have many authors. class User { /** @var string */ public $name; /** @var Collection
*/ public $articles; } class Article { /** @var string…
mleko
  • 11,650
  • 6
  • 50
  • 71
7
votes
2 answers

DQL Query fails

I've got 2 tables in an MySQL DB, im using doctrine 1.2 and symfony 1.4.4 Installedbase and Spare Installedbase: ib_id app_id location and Spare: spare_id app_id amount Now i want to join the to tables to show how many of the app are in the…
iggnition
  • 356
  • 6
  • 19
7
votes
2 answers

Combine IS NULL and :value in Doctrine 2 DQL

Since other (old) questions didn't get proper answers, I'll try it again: I regularly come across a scenario, where I want to query an entity with a specific value: $query = $em->createQuery('SELECT e FROM Entity e WHERE e.parent =…
Matheno
  • 4,112
  • 6
  • 36
  • 53
7
votes
2 answers

Update query with LIMIT ( setMaxResults ) in doctrine2 using createQueryBuilder not working

I have the following code $qb = $this->createQueryBuilder('cs') ->update() ->set('cs.is_active', 1) ->where('cs.reward_coupon = :reward_coupon') ->setMaxResults($limit) ->setParameter('reward_coupon',…
acj89
  • 258
  • 2
  • 6
7
votes
3 answers

Doctrine query: delete with limit

I am trying to delete only x objects with a delete query from Doctrine. And since there is no LIMIT in doctrine, we should use $query->setMaxResults($limit) instead. I am using Symfony2. However it does not work with the following query (with or…
msusplugas
  • 713
  • 3
  • 8
  • 16
7
votes
4 answers

With Doctrine what are the benefits of using DQL over SQL?

Can someone provide me a couple clear (fact supported) reasons to use/learn DQL vs. SQL when needing a custom query while working with Doctrine Classes? I find that if I cannot use an ORM's built-in relational functionality to achieve something I…
Ray
  • 40,256
  • 21
  • 101
  • 138
7
votes
3 answers

DQL many to many and count

I'm using Symfony 2 with Doctrine, and I've got two entities joined in a many to many association. Let's say I have two entities: User and Group, and the related tables on db are users, groups and users_groups. I'd like to get the top 10 most…
Lorenzo Marcon
  • 8,029
  • 5
  • 38
  • 63
6
votes
3 answers

Query Builder / DQL not working with INNER JOIN - Syntax Issue

I know I have a syntax isse here however I cant figure it out. I'm trying to do a SELECT and INNER JOIN of 5 tables but Symfony is complaining about the Entities in the JOIN are used before being defined. Actual error is as follows: [Semantical…
ElasticThoughts
  • 3,417
  • 8
  • 43
  • 58