dql

Can you join on a subquery with Doctrine 2 DQL?

落花浮王杯 提交于 2019-12-01 08:23:45
问题 Is there a way to access a joined entity's relation in the WITH clause of a join? Im trying to avoid using an IN clause with a subquery. Edit: Or is there a way to join on a subquery rather than using IN ? i.e. Making sure the joined object's t.final value is 1. Trying to Avoid This Query SELECT o FROM Entity\Order o WHERE o.status = :orderStatus AND o.id NOT IN ( SELECT o2.id FROM Entity\ServiceRequest s JOIN s.order o2 JOIN s.serviceType t WHERE s.status = :serviceStatus AND t.final = 1 )

Error in Nested SubQuery In DQL: Class '(' is not defined

独自空忆成欢 提交于 2019-12-01 06:02:47
I have a DQL as like below: SELECT at, count(at.id) FROM AccountTriple at JOIN at.property p JOIN at.account ac WHERE p.create_analytics = '1' GROUP BY at.property, at.value, ac.service As you can see, it has three joins. As 'at' and 'ac' both have large amount of data. In attempt to optimize it, I am trying to move the "p.create_analytics = '1'" checking before join to 'ac' to give it a smaller data set to join. I am trying to achieve something like this: SELECT at, count(at.id) FROM ( SELECT at FROM AccountTriple at JOIN at.property p WHERE p.create_analytics = '1' ) JOIN at.account ac GROUP

Error in Nested SubQuery In DQL: Class '(' is not defined

ぃ、小莉子 提交于 2019-12-01 04:26:07
问题 I have a DQL as like below: SELECT at, count(at.id) FROM AccountTriple at JOIN at.property p JOIN at.account ac WHERE p.create_analytics = '1' GROUP BY at.property, at.value, ac.service As you can see, it has three joins. As 'at' and 'ac' both have large amount of data. In attempt to optimize it, I am trying to move the "p.create_analytics = '1'" checking before join to 'ac' to give it a smaller data set to join. I am trying to achieve something like this: SELECT at, count(at.id) FROM (

Doctrine DQL dynamic ORDER BY parameter

被刻印的时光 ゝ 提交于 2019-12-01 00:50:41
Im trying to pass the ORDER BY column as a parameter in DQL, like below: $this->em->createQuery("SELECT t FROM Entities\Topic t ORDER BY :order") ->setParameters( array('order' => 't.name') )->getResult(); I guess it doesn't work because setParameter will escape :order, however the below solution doesn't seem very good: $order = 't.name'; // Dynamic value $this->em->createQuery("SELECT t FROM Entities\Topic t ORDER BY $order") ->getResult(); Is there a better way to solve this? In that case use Doctrines Querybuilder : $order = 't.name'; // Dynamic value $qb = $this->_em->createQueryBuilder();

IFNULL in Symfony2 Doctrine query builder

雨燕双飞 提交于 2019-12-01 00:42:15
How is the IFNULL of SQL implemented in Symfony2 Doctrine Query Builder? Let's say I have this query: select * from ticket order by IFNULL(modified_date, '2000-01-01') DESC, created_date DESC I have this DQL: $this->qb->select("t, c.name") ->from("Ticket", "t"); $this->qb->orderBy("t.modifiedDate", "DESC"); $this->qb->addOrderBy("t.createdDate", "DESC"); Now how to add the IFNULL part? ArVan Ok, done some research and found that there is no such implementation. Googled a little more, and got that this kind of missing features can be added to Doctrine as own functions. Found this extension on

Any way of using SHA1 in DQL

你。 提交于 2019-12-01 00:21:08
DQL below generates an error: [Syntax Error] line 0, col 42: Error: Expected known function, got 'sha1' Any way of using SHA1? public function findIdByDql($hashId) { $em = $this->getEntityManager(); $query = $em->createQuery('DELETE FROM CarBrandBundle:Brands b WHERE sha1(b.id) = :id') ->setParameter('id', $hashId) ->execute(); return; } You need to create your own function which will translate sha1 function. Your app/config/config.yml file: doctrine: orm: dql: string_functions: sha1: YourBundle\DQL\Sha Your src/YourBundle/DQL/Sha.php file: namespace YourBundle\DQL; use Doctrine\ORM\Query\AST

IFNULL in Symfony2 Doctrine query builder

我的梦境 提交于 2019-11-30 19:34:22
问题 How is the IFNULL of SQL implemented in Symfony2 Doctrine Query Builder? Let's say I have this query: select * from ticket order by IFNULL(modified_date, '2000-01-01') DESC, created_date DESC I have this DQL: $this->qb->select("t, c.name") ->from("Ticket", "t"); $this->qb->orderBy("t.modifiedDate", "DESC"); $this->qb->addOrderBy("t.createdDate", "DESC"); Now how to add the IFNULL part? 回答1: Ok, done some research and found that there is no such implementation. Googled a little more, and got

Doctrine 2 DQL CASE WHEN in Count

我的梦境 提交于 2019-11-30 18:42:24
I have this Query in native MySQL Code SELECT * FROM `turn` LEFT JOIN ( poi ) ON ( turn.id = poi.turn_id ) GROUP BY turn.id ORDER BY count( case when poi.image = 1 then 1 else null end) DESC; I need to rebuild this in Doctrine 2 DQL My attempt so far is this: SELECT t, COUNT((CASE WHEN Bundle\Entity\Poi p.image = 1 then 1 ELSE NULL END)) AS num FROM Bundle\Entity\Turn t JOIN t.pois p GROUP BY t.id ORDER BY num DESC And im getting this error: An exception has been thrown during the rendering of a template ("[Syntax Error] line 0, col 99: Error: Expected end of string, got '.'") in Bundle:Admin

Any way of using SHA1 in DQL

[亡魂溺海] 提交于 2019-11-30 18:04:15
问题 DQL below generates an error: [Syntax Error] line 0, col 42: Error: Expected known function, got 'sha1' Any way of using SHA1? public function findIdByDql($hashId) { $em = $this->getEntityManager(); $query = $em->createQuery('DELETE FROM CarBrandBundle:Brands b WHERE sha1(b.id) = :id') ->setParameter('id', $hashId) ->execute(); return; } 回答1: You need to create your own function which will translate sha1 function. Your app/config/config.yml file: doctrine: orm: dql: string_functions: sha1:

Using COLLATE inside Doctrine DQL Query (Symfony2)

会有一股神秘感。 提交于 2019-11-30 15:34:48
I can't find anything related to using COLLATE in a DQL query with Doctrine (and ofcourse it doesn't seem to work). My specific problem: I have a table with utf8_general_ci charset. I have one specific field in it which has accented characters (like 'á', 'ű', 'ő' etc.) A basic comparison with utf8_general_ci is not able to determine the difference between regular chars and their accented pairs (a = á, u = ű, o = ő), which is perfectly fine for me for the majority of the queries that land on that table! So if I have let's say: col1 | col2 ------|------- 1 | árvíz ------|------- 2 | arviz This