dql

From Doctrine Query to QueryBuilder in a Simfony2 entity field type

独自空忆成欢 提交于 2019-12-03 09:22:20
I'm using the entity Field Type in a Symfony2.1 form. Here, I'm going to use the query_builder param to return only entities that matches a long-complex query (see the example in the official docs ). Obviously the query_builder param for the entity field type accepts a Doctrine QueryBuilder object. On the other side, I have large entity repositories with complex DQL queries obtained by the EntityManager 's createQuery() function which returns a Doctrine Query object. So, I cannot directly use all these queries in the entity field type. Moreover, rewriting all the queries for the use with a

Leave out discriminator part of Doctrine' generated SQL

自作多情 提交于 2019-12-03 06:53:42
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 queries this part of the WHERE clause makes it not possible to use some indexes that are defined. This

How to specify null value as filter in a Doctrine query?

我怕爱的太早我们不能终老 提交于 2019-12-03 06:28:17
问题 I am using Doctrine 1.1 in Zend. I am trying to write a query that will return records that have a null value in a certain column. $q = Doctrine_Query::create() ->select('a.*') ->from('RuleSet a') ->where('a.vertical_id = ?', null); $ruleset_names_result = $q->execute(array(), Doctrine::HYDRATE_ARRAY); I have three records in the ruleset table which have a NULL value in the vertical_id column yet the query doest not find these. Appreciate the help. Sid. 回答1: I use doctrine with symfony, and

Doctrine: Multiple (whereIn OR whereIn) query?

荒凉一梦 提交于 2019-12-03 03:17:31
I'm having trouble crafting a fairly simple query with Doctrine... I have two arrays ($countries, $cities) and I need to check whether database record values would match any inside either. I'm looking for something like: ->whereIn('country', 'city', $countries, $cities) ... with 'country' being a WHERE IN for $countries and 'city' being a WHERE IN for $city. I could separate the two out but the needed query has lots of other conditions so that's not possible. The resulting SQL I'm after would be: SELECT ... WHERE ... AND ... AND ... AND ('country' IN (1,2,3) OR 'city' IN (7,8,9)) AND ... AND .

doctrine2 queryBuilder must return only result matching with array values (ids): 0/Null and/or One and/or Many id(s) have to return One result

本小妞迷上赌 提交于 2019-12-02 08:14:14
问题 I have an array of collection named $configurations . This array matches of my Entity Configuration.php connected to Product.php as a ManyToMany . Now I have another entity named WorkType.php which is connected too to Configuration.php by a ManyToMany . The goal is to recover the product who has O/Null or Many configurations for the current work type. By default I have a product without configurations, but user could choose by checkboxes a O/Null or One or Many configurations available for a

Doctrine2 in ZF2 - DQL gives different result than findOneBy method

核能气质少年 提交于 2019-12-02 03:38:10
问题 I have this entity: /** * User state. * * @ORM\Entity(repositoryClass="User\Repository\StateRepository") * @ORM\Table(name="user_state") */ class State implements StateInterface { /** ONE-TO-ONE BIDIRECTIONAL, OWNING SIDE * @var User * @ORM\Id * @ORM\OneToOne(targetEntity="User\Entity\User", inversedBy="state") * @ORM\JoinColumn(name="user_id", referencedColumnName="id") */ protected $user; /** ONE-TO-ONE UNIDIRECTIONAL * @var \Application\Entity\State * @ORM\Id * @ORM\ManyToOne(targetEntity=

Doctrine2 in ZF2 - DQL gives different result than findOneBy method

只愿长相守 提交于 2019-12-02 00:04:21
I have this entity: /** * User state. * * @ORM\Entity(repositoryClass="User\Repository\StateRepository") * @ORM\Table(name="user_state") */ class State implements StateInterface { /** ONE-TO-ONE BIDIRECTIONAL, OWNING SIDE * @var User * @ORM\Id * @ORM\OneToOne(targetEntity="User\Entity\User", inversedBy="state") * @ORM\JoinColumn(name="user_id", referencedColumnName="id") */ protected $user; /** ONE-TO-ONE UNIDIRECTIONAL * @var \Application\Entity\State * @ORM\Id * @ORM\ManyToOne(targetEntity="Application\Entity\State", fetch="EAGER") * @ORM\JoinColumn(name="state_id", referencedColumnName="id"

How to select discriminator column in doctrine 2

北慕城南 提交于 2019-12-01 17:52:19
I need some help when select only discriminator column from doctrine 2 when run the DQL below SELECT p.type FROM AppBundle\Entity\Product p type is discriminator column in entity AppBundle\Entity\Product @ORM\DiscriminatorColumn(name="type", type="smallint")` @ORM\DiscriminatorMap({ "0" = "AppBundle\Entity\Product", "1" = "AppBundle\Entity\Product\SingleIssue", "2" = "AppBundle\Entity\Product\CountBasedIssue", "3" = "AppBundle\Entity\Product\TimeBasedIssue" }) I know that type is not a real property in entity, but is there anyway for me to do that? Thanks in advance! Updated After 2 days for

Doctrine 2 Restricting Associations with DQL

被刻印的时光 ゝ 提交于 2019-12-01 12:27:51
问题 There seems to be an over sight in Doctrine 2.1 where it isn't easy to return a subset collection for an association. http://www.doctrine-project.org/docs/orm/2.1/en/reference/limitations-and-known-issues.html#restricing-associations The docs recommend to write a repository find method, which makes sense because that was the first thing I though of doing. However without having a reference to the EntityManager within an Entity I can't see how you would retrieve the association's Repository

Cumulative DQL with Doctrine

纵然是瞬间 提交于 2019-12-01 11:23:52
Im having a hard time working out a proper DQL to generate cumulative sum. I can do it in plain SQL but when it comes to DQL i cant get hold of it. Here is how it looks in SQL: SELECT s.name, p.date_short, p.nettobuy, (select sum(pp.nettobuy) as sum from price pp where pp.stock_id = p.stock_id and p.broker_id = pp.broker_id and pp.date_short <= p.date_short) as cumulative_sum FROM price p left join stock s on p.stock_id = s.id group by p.stock_id, p.date_short order by p.stock_id, p.date_short Thanks Hey, I have check the documentation for Doctrine 1.2, and the way to create the query is (put