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
1
vote
1 answer

Symfony 2 findBy order result case insensitive

$this->get('bundle_name.entity_name.service')->findBy(array(), array('name' => 'ASC')); This gives the following result when displaying the names: A B C b How can I order the result case insensitive? So that the result would be like this when…
MHarteveld
  • 167
  • 2
  • 8
1
vote
1 answer

How to filter by child value in Symfony PHPCR Query Builder

Trying to build a query in symfony that finds all PHPCR nodes of a certain document type with a given name and filters by the city of its Address child document. $qb->from() ->document('My\Bundle\Document\MyDocument', 'm') …
Daniel
  • 13
  • 4
1
vote
2 answers

doctrine dql exception: Illegal offset type in /var/www/Symfony/vendor/doctrine/orm/lib/Doctrine/ORM/Query/SqlWalker.php line 601

I want to produce a DQL for following MySQL query: SELECT * FROM `folders` AS `t` WHERE `t`.`Library` = @myLib AND AND `t`.`Id` NOT IN ( SELECT DISTINCT(`f`.`Id`) FROM `folders` AS `f` JOIN `folders` AS `ff` ON (`f`.`Position` LIKE…
Javad
  • 4,339
  • 3
  • 21
  • 36
1
vote
1 answer

Doctrine DQL execute passing params

I used this DQL in Doctrine $q->update('product') ->set('quantity','?') ->where('id=?'); $q->execute(array(20,5)); I check the server for the query and this the generated sql UPDATE product SET quantity = '20', updated_at = '5' WHERE (id =…
1
vote
1 answer

Doctrine 2 throws NonUniqueResultException on getSIngleScalarResult

i created a query using query builder and now i want to get how many records are in the result but from some reason it throws me NonUniqueResultException Here is the code $VideoQueueRepo =…
user3018350
1
vote
1 answer

How to query UPDATE SET field = !field in Doctrine 2

I want to make a query like "UPDATE category c SET c.display = !c.display" but I get an exception. My code: $qb = $entityManager->createQueryBuilder(); $q = $qb->update('Category', 'c') ->set('c.display', '!c.display') …
1
vote
1 answer

Doctrine QueryBuilder - Exclude articles linked to specific themes

I'm working on a Symfony2 project using Doctrine2. I have a 'article' and a 'theme' table in a many-to-many relationship. I am trying to get every articles except those linked to theme 35. $query = $this->createQueryBuilder('art') …
gobtronic
  • 331
  • 1
  • 2
  • 12
1
vote
1 answer

How to get the raw query from EntityRepository from the controller

I need to get the raw query as a string, something like this. $query = 'SELECT p FROM GabrielUploadBundle:Image p WHERE p.upvotes > x ORDER BY p.createdAt ASC'; My custom "findAllNewestByVotes" method contains the query. class ImageRepository…
user3531149
  • 1,519
  • 3
  • 30
  • 48
1
vote
2 answers

delete several rows where attribute = x

I need to delete all rows where the image_id = x applies like this DELETE FROM `ImageVoters` WHERE image_id =1 How do I do this using DQL? Since im trying to delete several rows at once the remove() function won't work EntityManager#remove()…
user3531149
  • 1,519
  • 3
  • 30
  • 48
1
vote
2 answers

Using RAND() function from SQL with Doctrine2

I've been stuck with this for about 10 hours I need to use this query (an optimized version of ORDER BY RAND) public function findAllRandom() { return $this->getEntityManager() ->createQuery( 'SELECT p FROM GabrielUploadBundle:Image…
user3531149
  • 1,519
  • 3
  • 30
  • 48
1
vote
1 answer

I would like to get the records related to text by DQL

DATABASE: id | name | // ... ==================== 1 | London | 2 | Paris | 3 | Moscow | 4 | New York | // ... TEXT: This is a big city. I live in this town. I like the name of city. 'New York' is very cool. However, I have to go to…
R.Atim
  • 367
  • 1
  • 7
  • 16
1
vote
1 answer

getQuery (Doctrine) is running VERY VERY slow

I have setup a virtualbox running Linux Mint 16 x64 for R&D with Symfony2/Doctrine2. I installed Symfony via composer and it installed Doctrine with it. I setup this up about 2-3 weeks ago so the version I'm using should be latest or at least very…
mrjayviper
  • 2,258
  • 11
  • 46
  • 82
1
vote
1 answer

Plain SQL and DQL and Doctrine 2 ORM better performance?

I tried implementing all of the three ways to fetch some data. I noticed that doctrine 2 ORM was faster than others. But when I searched about performance of the three on internet, I noted that SQL and DQL work more faster. If it is so, then what is…
1
vote
1 answer

Doctrine Query: How to Query with Date Range?

Basically, I want to query using a date range as follows: $qb = $this->createQueryBuilder("c"); if ($createDateStart) { $createDateStart = $createDateStart->format('d-M-Y'); $qb->where("c.createDate >=…
1
vote
2 answers

Doctrine - Can I use real SQL (not DQL) in a ->andWhere()?

I'm using Doctrine, a PHP ORM. I have created a Doctrine Query, and I need more control. So I've started to use the ->andWhere(...) methods to add new where clauses. However I need to do a subquery based on another table, like…
Amandasaurus
  • 58,203
  • 71
  • 188
  • 248