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

Doctrine filtering by multiple columns

I need to filter in doctrine through multiple fields like the following: SELECT company , state FROM employees WHERE (company, state) <> ('xxxxx', 'xxxx') AND (company, state) <> ('xxxx', 'xxxx') GROUP BY company, state I tried the following…
jotamolas
  • 11
  • 4
0
votes
0 answers

Zf2 Doctrine2 - Can not add relationship in existing database tables which does not have any FK

I am currently doing ZF2 project with Doctrine2. I have existing database where tables does not have foreign key constraints and any relation. Using doctrine can I generate schema based on relation without foreign key constraints. I tried to add the…
0
votes
1 answer

doctrine QueryBuilder arithmetic operation

I am trying to do an arithmetic operation with doctrine Query Builder and assign the result to an alias. Following is an example from geeksengine that I'd like to "convert" to doctrine QueryBuilder: /* Query 1: This query calculates the total price…
Lowtower
  • 25
  • 5
0
votes
1 answer

Doctrine CASE WHEN with WHERE IN statement

Good day, everyone! I have following Doctrine query to retrieve some CTI entities: SELECT s.id FROM CRM\SpendBundle\Entity\Spend s WHERE (CASE WHEN s INSTANCE OF 'CRM\BusinessTripBundle\Entity\BusinessTrip' THEN 'Business Trip' …
Stepan Yudin
  • 470
  • 3
  • 19
0
votes
2 answers

How do I use SQL LEFT() in Symfony2 query builder?

Here's the line that's making my query fail. $query = $query->where('a.field LIKE :keyword OR LEFT(a.otherfield, 3) = LEFT(:keyword, 3)'); I get this error: [Syntax Error] line 0, col 104: Error: Expected known function, got 'LEFT' This SQL code…
chrislebaron
  • 269
  • 3
  • 14
0
votes
1 answer

Ordering by a generated field in Doctrine 1.2

I'm using a preDqlSelect() callback to add a "virtual field". But the validation of my query must be happening before the callback get fired because I can't order by that new field when I query that model. Here's my callback: class Artist extends…
mattalxndr
  • 9,143
  • 8
  • 56
  • 87
0
votes
1 answer

Syntax Error Symfony2 Query

Hi I have following join query. return $this->getEntityManager() ->createQuery( "SELECT t1.taskId,t1.title,t1.dueDate,t1.modified,cb.forename,cb.surname,up.profilePhotoPath, (SELECT tp.metaData,tp.content FROM…
Sunil Rawat
  • 709
  • 10
  • 41
0
votes
1 answer

Symfony 2 & doctrine2 - how to use column name as array key when using join in doctrine query builder?

My problem I am performing a join using doctrine2 query builder and symfony3. My controller contains following code: $rp_konta = $this->getDoctrine()->getRepository('AppBundle:konto'); $query = $rp_konta->createQueryBuilder('p') …
Abdel5
  • 1,112
  • 3
  • 16
  • 39
0
votes
1 answer

DQL: Join table and return all results when at least one joined column fulfills a condition

I have two entities in Doctrine: oneToMany between Post and Comments. Comments are owned by a User. I want to retrieve all posts and comments for which at least one comment is owned by a certain user. What would be the proper way of achieving that…
user2626210
  • 115
  • 5
  • 13
0
votes
1 answer

limit columns returned in relationnal entity symfony2

Is it possible to filter an entity and display only few columns in symfony2? I think I can do a custom query for this, but it seems a bit dirty and I am sure there is a better solution. For example I have my variable $createdBy below, and it…
Nicolas D
  • 1,182
  • 18
  • 40
0
votes
1 answer

Add selected from join table fields in Entity, Symfony

When I run: $this->createQueryBuilder('debtor') ->join('debtor.deals', 'deal') ->addSelect('...something... as closed_deals_count') ->getQuery() ->getSingleResult() It results in the following structure: array:3 [ 0 => Debtor {...}, …
0
votes
0 answers

Doctrine 2 setParameter not working on string

$query = $em->createQuery('SELECT u FROM Entity\User u where u.first_name = :name'); $query->setParameter('name', 'Fawad'); $users = $query->getResult(); foreach ($users as $items) { echo $items->getId() . " " . $items->getFirstName() .…
0
votes
1 answer

Symfony2 - Set value of checkboxes in form from ORM DQL

I'm creating a form that is supposed to filter a custom query list in Symfony2(ver 2.3) using LexikFilter Bundle. Project setup: Symfony2 :2.3.7 LexikFilter Bundle : 3.0.8 Doctrine ORM 2.4 The project consist of entities having a n:m relationship…
Raymond A
  • 763
  • 1
  • 12
  • 29
0
votes
1 answer

Symfony 2.8 : DQL query to display an arraycollection

I'm a beginner on Symfony 2 and I have a problem with a DQL query : I'm trying to display a property that is an ArrayCollection. Here's my case : Two classes joined together with a "ManyToOne" and "OneToMany" DishGrade.php : /** * @var Dish…
Erik F.
  • 3
  • 1
0
votes
1 answer

mysql order by date and sort parent table

i have this two table: id | name 1 | Mike 2 | Jack id | id_client | title | due_date | sort 1 | 1 | Xxxx | 2016-01-22 | 0 2 | 1 | Xxxx | 2016-01-24 | 1 3 | 2 | Xxxx | 2016-01-28 | 0 I need to order the first by…
Ste
  • 1,497
  • 8
  • 33
  • 63