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

createQueryBuilder IN clause

I´m working with Symfony2 and I need to execute this SQL for example: select detformacion.* from detformacion left join formacion on detformacion.formacion_id = formacion.id left join detcurso on formacion.id…
ikerib
  • 781
  • 3
  • 11
  • 28
5
votes
1 answer

How to filter data with nested object in GraphQL

query { comp(func: eq(dgraph.type,"ServiceTemplate")) { topologytemplate{ nodetemplates { name namespace @filter (eq(url,"a_url")){ url } } } } } Using…
5
votes
3 answers

How to return object from a DQL query?

I have written a DQL query in Doctrine 2: $qb->select('r.position') ->from('\Entities\Races', 'r') ->where($qb->expr()->eq('r.entrantId', ':entrant_id')) ->setParameter('entrant_id', $this->entrantId); $query = $qb->getQuery(); $aRaces =…
Mr B
  • 3,980
  • 9
  • 48
  • 74
5
votes
2 answers

Doctrine - delete all entities

I have problem with deleting all rows in database. I can't find out how to do it. I'm using Symfony and Doctrine. Somewhere I read, that it isn't possible "normal" way, but I can do it by DQL (createQuery), but I don't know syntax. public function…
Tomato
  • 129
  • 1
  • 1
  • 6
5
votes
1 answer

Doctrine 2 DQL: Cannot reuse named parameter?

I find that I cannot do something like below, notice ':user' is used twice $query = $em->createQuery('select p from Application\Models\Project p WHERE p.owner = :user OR :user MEMBER OF…
Jiew Meng
  • 84,767
  • 185
  • 495
  • 805
5
votes
1 answer

How to fetch data from many to many relation ship third table using symfony2 doctrine DQL

1)Category Entity: /** * Category * * @ORM\Table(name="category") * @ORM\Entity(repositoryClass="AppBundle\Repository\CategoryRepository") */ class Category { /** * @var int *…
somesh
  • 528
  • 2
  • 10
  • 26
5
votes
2 answers

Symfony2 - Custom DQL Function Registered But Does Not Exist

I am desperatelly trying to include the LEVENSHTEIN function in Symfony2, however, I still receive errors. Specs + what I've done so far: PostgreSQL 9.3 LEVENSHTEIN included in fuzzystrmatch extension Tested the function via shell execution. Works…
chrisp
  • 569
  • 4
  • 24
5
votes
1 answer

Doctrine DQL and Namespaces (relative only?)

i noticed that if i try to do soemthing like $query = $em->createQuery('SELECT u FROM \Application\Entities\User u'); i get [Semantical Error] line 0, col 14 near '\Application\Entities\User': Error: Class '\' is not defined. if i do $query =…
Jiew Meng
  • 84,767
  • 185
  • 495
  • 805
5
votes
1 answer

How to export millions of rows from MySQL to CSV via PHP without exhausting memory?

So I have this table: mysql> DESCRIBE table; +-------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra …
D4V1D
  • 5,805
  • 3
  • 30
  • 65
5
votes
2 answers

Doctrine2 , get entities order by count of a many to many property

I have two entities Article User Article has a relation to user named 'likedByUsers' Now, I would like to get the articles order by number of likes, but: I don't want to have a property 'numberOfLikes' because it's too much problem to keep it…
allan.simon
  • 3,886
  • 6
  • 35
  • 60
5
votes
3 answers

Cannot select entity through identification variables without choosing at least one root entity alias

Ads entity is described by geographic information: Country> Region>County. The Ads entity is only linked with County. Consequently, retrieving Ads by countries will require us joining entities twice. My goal is counting the number of Ads for a given…
Amine Jallouli
  • 3,919
  • 8
  • 36
  • 73
5
votes
1 answer

Error in Nested SubQuery In DQL: Class '(' is not defined

I have a DQL as like below: SELECT at, count(at.id) FROM AccountTriple at JOIN at.property p JOIN at.account ac WHERE p.create_analytics = '1' GROUP BY at.property, at.value, ac.service As you can see, it has three joins. As 'at' and 'ac' both have…
Rana
  • 5,912
  • 12
  • 58
  • 91
5
votes
2 answers

Doctrine Search by count on join Table

I have a problem with my nemesis: SQL/DQL I have an entity: Style and an entity Vote. A Style can have a lot of Votes (as you can imagine) and one Vote is linked to exactly one Style. I now want to search for Styles that have less Votes than a…
Loki
  • 113
  • 1
  • 7
5
votes
2 answers

Symfony 2 Doctrine COUNT

I have in my table "Artiste" one column "valideAdmin" who takes value 1 or 0. I try to make a simple count to return the number of entries in my table where "valideAdmin" is to 1: $repo = $this ->getDoctrine() …
Macbernie
  • 1,303
  • 6
  • 24
  • 48
5
votes
1 answer

DQL - leftJoin() error: Expected Literal, got 'JOIN'

This code: $builder->select('p') ->from('ProProposalBundle:Proposal', 'p') ->leftJoin('ProProposalBundle:Proposal:Vote', 'v') ->leftJoin('ProUserBundle:User', 'u') ->andWhere('v.proposal = p') ->andWhere('v.user = u') …
Manolo
  • 24,020
  • 20
  • 85
  • 130