dql

From Doctrine Query to QueryBuilder in a Simfony2 entity field type

半城伤御伤魂 提交于 2020-01-01 03:31:11
问题 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

Symfony 2 join not working doctrine

萝らか妹 提交于 2019-12-31 06:42:12
问题 I have 2 entities with a OnrtoMany relationship, Vehicle that has many Jobs. I am trying to create this function at the VehicleRepository: public function findByJobXVehicle($dateStart = null, $dateEnd=null){ $query = $this->createQueryBuilder('v') ->select('v.plateNumber','SUM(j.kmOdoEnd - j.kmOdoStart) as dist') ->join('v.jobs', 'j') ->groupBy('v.plateNumber'); $q = $query->getQuery()->getResult(); //get_class($q[0]); return $q; } The object vehicle is this: <?php namespace TeamERP

How to select discriminator column in doctrine 2

China☆狼群 提交于 2019-12-30 18:57:05
问题 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

Using COLLATE inside Doctrine DQL Query (Symfony2)

你说的曾经没有我的故事 提交于 2019-12-30 05:04:26
问题 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

Using COLLATE inside Doctrine DQL Query (Symfony2)

大城市里の小女人 提交于 2019-12-30 05:04:17
问题 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

CASTING attributes for Ordering on a Doctrine2 DQL Query

拜拜、爱过 提交于 2019-12-28 03:53:47
问题 I am trying to get Doctrine2 Entities , ordered by their ID which apparently is a String even though it contains only Numbers. So what I would like to do is something like this: SELECT entity1, cast (entity1.id AS integer) AS orderId FROM Namespace\Bla\MyEntity ORDER BY orderId Is there a way to do something like this in Doctrine2 ? Or, what would be the best practise to get my Result if i can't change the type of the id ( due to customer requirements of course )? Attention : I am not asking

Symfony 2 join not working doctrine and MySQL

心不动则不痛 提交于 2019-12-25 12:17:28
问题 Note: this post was solved using this method, the problem was in one of my entities, so any thing I tried that would in normal conditions work, was bad functioning because of that. I do not know how to mark it now. I have the following repository entities: Vehicle, Job, FuelPurchase. For intance vahicle: /** * @ORM\Entity * @ORM\Table(name="vehicle") * @ORM\Entity(repositoryClass="TeamERP\TransportBundle\Entity\VehicleRepository") */ class Vehicle { /** * @ORM\Column(type="integer", name="id

Symfony2 doctrine ManyToMany relation

会有一股神秘感。 提交于 2019-12-25 03:29:13
问题 I'm a beginner on Synfony2 and doctrine usage. I've created two entities as following : For EndUser Entity (extension of FOSUserBundle ): /** * EndUser * * @ORM\Table() * @ORM\Entity(repositoryClass="Core\CustomerBundle\Entity\EndUserRepository") */ class EndUser extends BaseUser { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @ORM\ManyToMany(targetEntity="Core\GeneralBundle\Entity\Discipline", mappedBy=

How to get entities in a many-to-many relationship that do NOT have a corresponding linked entity with DQL and Doctrine?

☆樱花仙子☆ 提交于 2019-12-24 12:43:53
问题 I have a standard many-to-many relationship set up. Entity A can have many of Entity B, and vice versa . I'm trying to get a list of all Entity A that do NOT have any corresponding Entity B. In SQL, I'd run a query like this: SELECT a.* FROM entity_a a LEFT JOIN a_b r ON r.AID = a.id WHERE r.BID IS NULL In this query, a_b is the linking table. I'm trying to write a DQL statement (or use some other method) to get the same result, but the following does not work: SELECT s FROM VendorMyBundle

Select specific columns from a repository in Doctrine 2

浪子不回头ぞ 提交于 2019-12-24 04:44:09
问题 First, we know that depending on the amount of columns in a query, may increase the response time. In Doctrine call the following store, which has a relationship and it brings all the columns of both entities. public function index() { $this->students = $this->model->getRepository()->findAll(); } But thinking about the statement that I gave earlier, the return of this repository is more time consuming than if it was a non-relationship? And other questions. Can I select the columns that I want