dql

Request on key/value in a JSON type field with Doctrine2

耗尽温柔 提交于 2021-02-08 13:18:18
问题 I'm trying to figure out how, in a symfony 3.4 app, to retrieve (through a repository method, with a DQL request for example) entities depending on a value for a specific key in a "json" typed column. Saw there's some stuff possible with postgre but I didnt find anything with mariaDB Let's say I get an entity Letter with this property : /** * * @ORM\Column(type="json") */ private $metadatas; which contains, for example: { "key1": "value", "key2": "value" } How can I, or, Is it possible to

WHERE … IN query with sub-query in Doctrine queryBuilder or equivalent

穿精又带淫゛_ 提交于 2021-01-28 07:01:34
问题 In my Symfony 4 project I have a User entity and a UserRepository . I'm trying to implement the equivalent of this SQL query in the QueryBuilder (Doctrine 2) or even in DQL . SELECT * FROM user WHERE account_manager_id IN (SELECT id FROM user WHERE account_manager_id = :managerAdminId AND roles LIKE '%ROLE_MANAGER%') Or maybe use a different syntax. I tried different things, but couldn't figure out how to write the WHERE ... IN with the sub-query. This is all I could come up with, which I don

DQL query returns: StateFieldPathExpression or SingleValuedAssociationField expected

跟風遠走 提交于 2021-01-28 02:51:00
问题 I have the following DQL query: public function findByIdJoinedToCodeExample($pageId) { $query = $this->getEntityManager() ->createQuery(' SELECT c FROM acmeStyleGuideBundle:codeExample c JOIN c.PageContent p WHERE p.codeExample = :cex' ) ->setParameter('cex', $pageId); try { return $query->getResult(); } catch (\Doctrine\ORM\NoResultException $e) { return null; } } It is attempting to retreive data from an entity called codeExample which has a ManyToOne relationship with an entity called

DQL query returns: StateFieldPathExpression or SingleValuedAssociationField expected

主宰稳场 提交于 2021-01-27 23:50:00
问题 I have the following DQL query: public function findByIdJoinedToCodeExample($pageId) { $query = $this->getEntityManager() ->createQuery(' SELECT c FROM acmeStyleGuideBundle:codeExample c JOIN c.PageContent p WHERE p.codeExample = :cex' ) ->setParameter('cex', $pageId); try { return $query->getResult(); } catch (\Doctrine\ORM\NoResultException $e) { return null; } } It is attempting to retreive data from an entity called codeExample which has a ManyToOne relationship with an entity called

Doctrine - how to check if a collection contains an entity

自作多情 提交于 2020-12-05 10:02:11
问题 I have two entities User and Article with many-to-many relation as Article can have many authors. class User { /** @var string */ public $name; /** @var Collection<Article> */ public $articles; } class Article { /** @var string */ public $title; /** @var Collection<User> */ public $authors; } How I can find all Articles with specified (co)author using DQL? 回答1: Use MEMBER OF expression. Your DQL query could like like SELECT art FROM Article art WHERE :user MEMBER OF art.authors or using query

What is the difference between JOIN ON and JOIN WITH in Doctrine2?

一个人想着一个人 提交于 2020-12-02 07:07:57
问题 What is the difference between JOIN ON and JOIN WITH in Doctrine2? I couldn't find any relevant info in the manual. 回答1: ON replaces the original join condition, WITH adds a condition to it. Example : [Album] ---OneToMany---> [Track] Case One DQL FROM Album a LEFT JOIN a.Track t WITH t.status = 1 Will translate in SQL FROM Album a LEFT JOIN Track t ON t.album_id = a.id AND t.status = 1 Case Two DQL FROM Album a LEFT JOIN a.Track t ON t.status = 1 Will translate in SQL FROM Album a LEFT JOIN

What is the difference between JOIN ON and JOIN WITH in Doctrine2?

僤鯓⒐⒋嵵緔 提交于 2020-12-02 07:05:15
问题 What is the difference between JOIN ON and JOIN WITH in Doctrine2? I couldn't find any relevant info in the manual. 回答1: ON replaces the original join condition, WITH adds a condition to it. Example : [Album] ---OneToMany---> [Track] Case One DQL FROM Album a LEFT JOIN a.Track t WITH t.status = 1 Will translate in SQL FROM Album a LEFT JOIN Track t ON t.album_id = a.id AND t.status = 1 Case Two DQL FROM Album a LEFT JOIN a.Track t ON t.status = 1 Will translate in SQL FROM Album a LEFT JOIN