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
208
votes
20 answers

Doctrine - How to print out the real sql, not just the prepared statement?

We're using Doctrine, a PHP ORM. I am creating a query like this: $q = Doctrine_Query::create()->select('id')->from('MyTable'); and then in the function I'm adding in various where clauses and things as appropriate, like…
Amandasaurus
  • 58,203
  • 71
  • 188
  • 248
35
votes
3 answers

'where not in' query with doctrine query builder

Im trying to reproduce this query: SELECT * FROM `request_lines` where request_id not in( select requestLine_id from `asset_request_lines` where asset_id = 1 ) in doctrine query builder, I am stuck on the where request_id not in(select I currently…
Andrew Atkinson
  • 4,103
  • 5
  • 44
  • 48
31
votes
2 answers

Expression mysql NOW() in Doctrine QueryBuilder

How to use the expression mysql NOW() in doctrine querybuilder?
Ricardo Viana
  • 341
  • 1
  • 3
  • 6
23
votes
1 answer

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

I'm using the following code in the query builder, to select an average of score values, and the category entity to which that average belongs: $queryBuilder = $this->createQueryBuilder('s') ->resetDQLPart('select') ->select('AVG(s.score) as…
Michel Maas
  • 407
  • 1
  • 3
  • 9
18
votes
4 answers

How to fetch class instead of array in Doctrine 2

I am able to fetch my data from database by using this structure: $user = $this->getDoctrine() ->getRepository('AcmeDemoBundle:Emails') ->find(8081); When I do that, I am able to get my data like this: $user->getColumnNameHere(); Basically, I am…
flower58
  • 687
  • 2
  • 8
  • 15
17
votes
4 answers

Regex with Doctrine 2 query builder?

As per the title, how would one match on a regular expression with the Doctrine 2 query builder? Basically I'm trying to generate unique slugs. Here is my current implementation. I generate the slug. I then check to see if there are any slugs in…
Marc
  • 3,812
  • 8
  • 37
  • 61
14
votes
1 answer

Doctrine 2 PlainValue expected

I'm having trouble executing a Doctrine DQL Query. This is the error it gives me. Doctrine\Common\Annotations\AnnotationException: [Syntax Error] Expected PlainValue, got 'integer' at position 13 in property Base\Session::$lifetime. My code looks…
Rene Terstegen
  • 7,911
  • 18
  • 52
  • 74
12
votes
6 answers

How do I view the parameters in a query?

In order to debug my code I would like to see the explicit sql query that is executed. I create the query with createQueryBuilder, and the most explicit thing I achieved is having the raw query using: $qb->getQuery()->getSQL(); The problem is that…
guyaloni
  • 4,972
  • 5
  • 52
  • 92
11
votes
4 answers

Fetch multi-row, single-column array using Doctrine

I have a Doctrine fetch statement like this $query = "SELECT id FROM table LIMIT 2"; $result = $db->fetchAll($query); which returns the array like this: Array ( [0] => Array ( [id] => 1 ) [1] => Array ( [id] => 2 …
Pringles
  • 4,355
  • 3
  • 18
  • 19
11
votes
1 answer

Doctrine orderBy on SUM() field with alias

I am trying to do a simple query in doctrine but struggling. $query->select(array( 'app_title' => 'u.title', 'user_name' => 'u.user_name', 'first_used' => 'MIN(u.creation_time)', 'last_used' => 'MAX(u.stop_time)', 'total_usage'…
YorkshireDeveloper
  • 161
  • 1
  • 1
  • 6
10
votes
5 answers

How to get Array Results in findAll() - Doctrine?

I need to fetch all records in database as Array using findAll() in Doctrine, My Query is Something like this $result = $this->getDoctrine() ->getRepository('CoreBundle:Categories') …
Hari
  • 1,545
  • 1
  • 22
  • 45
10
votes
3 answers

Doctrine Query to find total number of Result in MySQL with LIMIT

I am trying to fetch the total number of rows found for specific query when LIMIT is applied. I successfully found the answer in PHP/MySQL, But I am not able to conver the logic in Zend/Doctrine. I am working with Doctrine 2.3/Zend 1.12. I dont want…
DonOfDen
  • 3,968
  • 11
  • 62
  • 112
8
votes
2 answers

How to write union query in doctrine?

I want to use union in doctrine, i searched a lot but didn't get any success, this is my union query in sql, how to convert this query in doctrine? select * from (select…
usii
  • 1,113
  • 1
  • 10
  • 17
8
votes
1 answer

Create query in entity form field

I need to fetch a list of countries, sorted by alphabetical order. Since I have the entity translated in four languages (english, french, spanish and chinese), I've used gedmo doctrine extensions in order to manage the translation. The problem is…
Manu
  • 563
  • 1
  • 5
  • 18
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
1
2 3
24 25