dql

Leave out discriminator part of Doctrine' generated SQL

南笙酒味 提交于 2019-12-20 20:39:16
问题 Assume the following AbstractPage model: /* * @ORM\Entity * @ORM\Table(name="page") * @ORM\InheritanceType("SINGLE_TABLE") * @ORM\DiscriminatorColumn(name="type", type="string") * @ORM\DiscriminatorMap * ({ * "page" = "Page", * "link" = "Link" * }) */ And the following DQL query: SELECT p FROM \Page\Model\AbstractPage The generated SQL will be: SELECT ... FROM page p0_ WHERE p0_.type IN ('page', 'link') Now to the question: how can I remove the WHERE clause from this query. On more complex

Doctrine DQL, class table inheritance and access to subclass fields

独自空忆成欢 提交于 2019-12-18 11:53:17
问题 I have a problem with a DQL query and entity specialization. I have an Entity called Auction , which is OneToOne relation with Item . Item is a mappedSuperclass for Film and Book . I need a query that could back a search engine, allowing the user to look for auctions with different properties AND selling items with different properties (it is the AND part that makes it challenging). The problem is that even though Auction has an association pointing to Item as such, I need to have access to

Doctrine 2: Query result as associative array

久未见 提交于 2019-12-18 11:47:45
问题 In my Repository class I use the following code to query: $query = $this->getEntityManager()->createQuery(" SELECT s.term, COUNT(s.term) AS freq FROM App\Entities\SearchTerm s GROUP BY s.term ORDER BY s.term ASC "); $result = $query->getResult(); The result I get is something like: array (size=4) 0 => array (size=2) 'term' => string '' (length=0) 'freq' => string '1' (length=1) 1 => array (size=2) 'term' => string 'foo' (length=3) 'freq' => string '1' (length=1) 2 => array (size=2) 'term' =>

doctrine2 dql, use setParameter with % wildcard when doing a like comparison

南楼画角 提交于 2019-12-18 10:40:56
问题 I want to use the parameter place holder - e.g. ?1 - with the % wild cards. that is, something like: "u.name LIKE %?1%" (though this throws an error). The docs have the following two examples: 1. // Example - $qb->expr()->like('u.firstname', $qb->expr()->literal('Gui%')) public function like($x, $y); // Returns Expr\Comparison instance I do not like this as there is no protection against code injection. 2. // $qb instanceof QueryBuilder // example8: QueryBuilder port of: "SELECT u FROM User u

DQL query with joining table and two join

痞子三分冷 提交于 2019-12-18 08:34:50
问题 I have 2 entity: /** * @ORM\Entity * @ORM\Table(name="users") */ class User { /** * @ORM\ManyToMany(targetEntity="Myapp\UserBundle\Entity\Group") * @ORM\JoinTable(name="user_groups", * joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}, * inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")} * ) */ protected $groups; ... } and /** * @ORM\Entity(repositoryClass="Myapp\UserBundle\Repository\GroupRepository") * @ORM\Table(name="groups") */ class

DQL query with joining table and two join

家住魔仙堡 提交于 2019-12-18 08:32:24
问题 I have 2 entity: /** * @ORM\Entity * @ORM\Table(name="users") */ class User { /** * @ORM\ManyToMany(targetEntity="Myapp\UserBundle\Entity\Group") * @ORM\JoinTable(name="user_groups", * joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}, * inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")} * ) */ protected $groups; ... } and /** * @ORM\Entity(repositoryClass="Myapp\UserBundle\Repository\GroupRepository") * @ORM\Table(name="groups") */ class

Doctrine Query Builder not working with UPDATE and INNER JOIN

大憨熊 提交于 2019-12-18 05:55:51
问题 In my repository I have this query: $qb = $this->getEntityManager()->createQueryBuilder(); $qb ->update('MyBundle:Entity1', 'e1') ->join('e1.Entity2', 'e2') ->set('e1.visibile', '1') ->andWhere('e2.id = :id')->setParameter("id", 123) ; throw this error [Semantical Error] line 0, col 66 near 'e2.id = :id': Error: 'e2' is not defined I have checked the relation and it is right. Is there any issue using join in query update? 回答1: You can not use join on update and delete queries. You have to use

Doctrine won't let me select specific fields

与世无争的帅哥 提交于 2019-12-18 04:05:28
问题 The symfony framework features an app/console file that can be executed via php to perform some maintenance tasks. It allows users to run DQL queries as well: # php app/console doctrine:query:dql --hydrate=array \ 'SELECT u.id, u.nameFirst, u.nameLast FROM DatabaseBundle:User u' array 0 => array 'id' => string '1' (length=1) 'nameFirst' => string 'jaroslav' (length=8) 'nameLast' => string 'rakhmatoullin' (length=13) 1 => array 'id' => string '2' (length=1) 'nameFirst' => string 'Båb Kåre'

Selecting from subquery in DQL

霸气de小男生 提交于 2019-12-17 19:28:21
问题 I would like to perform a SELECT from the results of a subquery in DQL. The equivalent of doing the following in SQL: SELECT * FROM ( SELECT foo1,foo2 FROM bar ) where foo1='something'; The problem I am running into is that it complains that Error: Class '(' is not defined The actual DQL that produces that error is: SELECT u FROM ( SELECT u, COUNT(u) as total FROM Utterance u LEFT JOIN u.recordings r WHERE r.speaker IS NULL OR r.speaker <> 5 GROUP BY u.id ) matched WHERE total < 5 So to

Doctrine ManyToMany Query

我是研究僧i 提交于 2019-12-14 01:24:33
问题 I have a Product Entity which has a ManyToMany relationship with a Taxon Entity. I want to find all the products that belong to the intersection of all Taxons. For instance I want to find all products that belong to taxons with IDs 1 and 2. Products {1,2,3} Taxons {1,2,3,4,5} ProductsToTaxons {{p1,t1},{p1,t2}, {p2,t2}} I want to retrieve the following set ONLY when querying products for taxons 1 and 2: Product {1} which is from {{p1,t1}, {p1,t2}} Okay, So here is the DQL that i tried... but