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

Convert SQL to DQL

I need to change this sql query to doctrine query or dql form. Is this possible? SELECT count(*) AS listenCount, l.post_id AS postId FROM (SELECT DISTINCT ll.user_id, ll.post_id FROM listen ll) l WHERE l.post_id IN (' . $id . ') GROUP BY …
AHS441
  • 144
  • 1
  • 2
  • 13
0
votes
1 answer

'Invalid schema name' error thrown by Doctrine, but the raw SQL seems to work

I'm using some custom DQL functions to filter rows by some JSONB fields in PostgreSQL. Here's my query function: private function findTopLevelResources(): array { return $this->createQueryBuilder('r') ->where("JSON_EXISTS(r.contents,…
gronostaj
  • 2,231
  • 2
  • 23
  • 43
0
votes
1 answer

Symfony - Discard association field during hydration process of an EntityType querybuilder

My Symfony (3.3) Form EntityType is displayed as a select input and lists all the clients we have in database. The client entity is associated to several other entities using lazy mode. When the select box is rendered, 204 DB queries are issued. I…
Stphane
  • 3,368
  • 5
  • 32
  • 47
0
votes
1 answer

Doctrine where Query- Logical order - Where(condition1 and [condition2 or condition3])

I'm currently writing a Shopware Plugin. Shopware uses Doctrine for Database operations. I would like to write a doctrine statement like this: Where(condition1 and [condition2 or condition3]) See my comment in the code. $builder =…
basti500
  • 600
  • 4
  • 20
0
votes
1 answer

How to get total users signed up per day using query builder

I have a user table with a created datetime field. What I want to do is parse the table and return how many users have signed up per day: 12/06/2017 | 5 12/06/2017 | 8 12/06/2017 | 7 12/06/2017 | 12 etc. I figured it would be best to use the…
HappyCoder
  • 5,985
  • 6
  • 42
  • 73
0
votes
1 answer

How to check if multiple records exist on database (laravel doctrine)

I want to confirm whether a collection of users exist on the database. So, say I have an array: $data = [ [ 'firstName' => 'Alastair', 'lastName' => 'Appleby' ], [ 'firstName' => 'Celine', 'lastName' =>…
A. Appleby
  • 469
  • 1
  • 10
  • 23
0
votes
1 answer

Getter and ManyToOne relationship doesn't work

I'm working on a symfony project and I have an entity (calling here ent) with several attribute one of them being a ManyToOne relationship: /** * @ORM\ManyToOne(targetEntity="RB\ABundle\Entity\Somethingelse", inversedBy="ent") *…
Sylvain Attoumani
  • 1,213
  • 1
  • 15
  • 34
0
votes
1 answer

DQL Function inside Switch Statement Returns 0 on var_dump, but DQL Function works perfectly when not in Switch Statement

I've got this Doctrine DQL query that works perfectly inside another function, but when I put it inside my switch statement, it returns 0, whether as array or as int. I can't for the life of me figure out why this is the case as it works perfectly…
BILL WAGNER
  • 155
  • 3
  • 13
0
votes
0 answers

How to select the number of entities in association in Doctrine query builder?

I'm filtering a table of clients using doctrine query builder Client entity have a field $orders /** * Bidirectional - One-To-Many (INVERSE SIDE) * @ORM\OneToMany(targetEntity="Orders", mappedBy="client", cascade={"persist"} ) * */ private…
fpilee
  • 1,918
  • 2
  • 22
  • 38
0
votes
1 answer

Doctrine query with join table

I'm trying to create this SQL query in a doctrine QueryBuilder SELECT count(DISTINCT d.id) FROM `discount` d JOIN `order_discount_relationships` od ON od.discount_id = d.id JOIN `orders` o ON o.id = od.order_id WHERE o.status = 3 My two entity…
Bouffe
  • 770
  • 13
  • 37
0
votes
1 answer

How to filter on Doctrine Entity Object?

So I have a database setup like this. Phone numbers belong to groupings. And users belong to groupings as well. I'm trying to figure out how to get all users that belong to a grouping but through the entity object instead of just a query if this…
Joseph Astrahan
  • 8,659
  • 12
  • 83
  • 154
0
votes
1 answer

How to make a DQL query in a OneToMany relation that exclude elements at a certain date?

I have a problem with a query in Symfony. I have two entities with a OneToMany relation: /** * Field * * @ORM\Table(name="field") * @ORM\Entity(repositoryClass="MyBundle\Repository\FieldRepository") */ class Field { . . . /** …
Rafael Bermúdez
  • 123
  • 4
  • 16
0
votes
0 answers

mysql Or doctrine 2 query [order by MAX]

can i do this in doctrine or mysql, NOte that created is a datetime field, and i don't want to do it by another field as i may need to do it by updated date that is also a datetime field $query = $querybuilder->select(array( 'obs.insStatus…
Waqar Haider
  • 929
  • 10
  • 33
0
votes
1 answer

GroupBy and date

I'm trying to get for each day, the amount of reservations. I have done this doctrine request : // prepare date for request $today = new DateTime('now'); $lastMonth = new DateTime('-30 days'); $qb ->select('r.reservationDate,…
Xero
  • 3,951
  • 4
  • 41
  • 73
0
votes
1 answer

RIGHT JOIN doctrine

Im trying to Right join in symfony. I tried as described here Doctrine 2 - Outer join query and here Symfony - Using Outer Joins with Doctrine ORM . $query = $em->getRepository('AppBundle:raports')->createQueryBuilder('r') ->select('r') …
hamzo
  • 195
  • 4
  • 14