Questions tagged [doctrine-query]

Doctrine Query Language (DQL) is one of the Doctrine 2 ORM key features, it is the option to write database queries in a proprietary object oriented SQL dialect.

Doctrine Query Language (DQL) is one of the Doctrine 2 ORM key features, it is the option to write database queries in a proprietary object oriented SQL dialect. Inspired by Hibernates HQL, this provides developers with a powerful alternative to SQL that maintains flexibility without requiring unnecessary code duplication.

More about Doctrine ORM you could fine on the project site, here.

370 questions
7
votes
1 answer

Doctrine - Query One-To-Many, Unidirectional with Join Table association from inversed side

My target is: Create universal association where first entity (eg. Category) can be used many times for other Objects (eg. Post, Article) Example Post has categories and Article has categories, but Article and Post are totally different entities.…
Griva
  • 1,618
  • 20
  • 37
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
1 answer

Symfony2 Doctrine Querybuilder select all

I'm currently working on a Service in SF2 that queries the database with the QueryBuilder using a class variable set with a repository-specific QueryBuilder in the constructor of this Service. Which means i would like to make use of this set…
ZvL
  • 793
  • 2
  • 11
  • 25
7
votes
2 answers

doctrine2 with codeigniter foreign key insert

I've following database schema - Now department, year and division tables are already filled with information. I now need to insert student data. Student data is to be imported from xls file (importing and parsing part is done). As you can see in…
SachinGutte
  • 6,947
  • 5
  • 35
  • 58
7
votes
2 answers

How to manage Doctrine queries with multiple db schemas

I have an entity A with a relation ManyToOne with B but A and B doesn't belong to the same DB schema. Entity 'A' belongs to MyBundle bundle, and entity 'B' belongs to MyOtherBundle bundle. The official documentation explain how to work with…
user1913526
  • 126
  • 1
  • 6
6
votes
1 answer

Magic Doctrine2 finders when field has underscore?

I'm having problems using find*() magic methods of Doctrine2 when the field has an underscore in between. $repository->findByName("Hello"); // Works $repository->findByIsEnabled(true); Entity 'Acme\SecurityBundle\Entity\Package' has no field…
gremo
  • 47,186
  • 75
  • 257
  • 421
6
votes
0 answers

Doctrine dql select as with spaces

I would like to know if it's possible to alias a column name with spaces in for example $query = "SELECT u.firstName AS 'First Name' FROM User u"; $result = $query->getResult( Query::HYDRATE_ARRAY );
Korush Mahdavieh
  • 541
  • 5
  • 15
6
votes
1 answer

Error: Invalid PathExpression. Must be a StateFieldPathExpression.

I'm working on a symfony project entity with query builder. When I try to run this function I get this issue. [Semantical Error] line 0, col 9 near 'category FROM': Error: Invalid PathExpression. Must be a StateFieldPathExpression. public…
vimuth
  • 5,064
  • 33
  • 79
  • 116
6
votes
5 answers

doctrine2 order by array with ids

How I can with doctrine2 order by array with ids ? I have this query: $qb = $this->createQueryBuilder('u') ->select('u', 'n', 'c') ->leftJoin('u.notifications', 'n') ->leftJoin('u.channel', 'c') ->andWhere('u.id IN…
5
votes
1 answer

Doctrine Query Builder Where Count of ManyToMany is greater than

Im using the Doctrine Query Builder, and have a very specific requirement that came through. I am using the ManyToMany field in my entity, related to User entity association (Array of User account entities). /** * @var ArrayCollection * *…
RedactedProfile
  • 2,748
  • 6
  • 32
  • 51
4
votes
1 answer

Doctrine generates incorrect SQL when combining aggregate fields (group by) and ordering (order by) in a query with Paginator

I have a simple bi-directional one-to-many relationship between Item and Valoracion (a review). The following query should get the average score and number of reviews for each Item, in descending order: $itemsQb =…
4
votes
1 answer

Nested select query in doctrine query builder

In a Symfony2 project: select * from ( select p.name as product, u.id, u.name from user u left join product_purchase pp on pp.user_id = u.id left join product p on pp.product_id = pp.product_id where p.type = 'something' …
quosal
  • 167
  • 1
  • 2
  • 10
4
votes
1 answer

DQL And Equivalent SQL Not Returning Same Number Of Result Set

Here is my doctrine query running code: $queryString = "SELECT ct, count(ct.id), IDENTITY(a.service) " . "FROM ConnectionTriple ct " . "JOIN ct.account_connection ac " .…
Rana
  • 5,912
  • 12
  • 58
  • 91
4
votes
1 answer

Doctrine Query from Mysql

I want to create a Doctrine Query: (Doctrine 2.3) SELECT * FROM `car` WHERE `plate` like '%' AND (`datetime` BETWEEN '2013-03-13 22:20:18' AND '2013-03-13 22:20:20') OR (`datetime` BETWEEN '2013-03-13 15:10:18' AND '2013-03-13 15:10:16') I tried…
DonOfDen
  • 3,968
  • 11
  • 62
  • 112
4
votes
1 answer

Doctrine Query Builder, CASE WHEN in ORDER BY

I'm trying to make query with ORDER BY like this in Native SQL ORDER BY CASE `promotion` WHEN 0 THEN `net_price` ELSE `promotion_price` END DESC, `net_price` DESC Something like this $qb->orderBy('CASE `products.promotion` WHEN 0 THEN…
Gustek
  • 3,680
  • 2
  • 22
  • 36
1
2
3
24 25