doctrine-orm

Doctrine query using Native SQL always returning empty array

牧云@^-^@ 提交于 2021-02-20 13:32:13
问题 I create a service with methods that run some queries, i want to use doctrine Native SQL but no matter which query i made it always return an empty array. There is something that i'm missing? Method from service MonthVacancySchedule: public function getTotalVacanciesByUnits() { $rsm = new ResultSetMapping(); $sql = 'SELECT nome_procedimento FROM programacao'; $query = $this->emi->createNativeQuery($sql, $rsm); $units = $query->getResult(); return $units; } The controller which i use the

DDD - Association mapping between bounded contexts using Doctrine 2

孤街浪徒 提交于 2021-02-18 12:50:28
问题 I am struggling to understand the right way to implement association mapping between two entities from different bounded contexts using Doctrine 2. Suppose that there are two "User" and "Post" entities that belong to "User" and "Content" bounded contexts, respectively. There is also a "User" concept in "Content" context that determines the author of a "Post" through a Many-To-One association. Therefore, "User" in "Content" context is simply a value object containing the user id. My question

Symfony: ManyToMany table extra columns

亡梦爱人 提交于 2021-02-15 06:49:50
问题 I have a many to many table for User and House , called user_house . Instead of just two columns: user_id and house_id, i want to add 3 more: eg action, created_at, updated_at. How can I do this? I cannot find any relevant docs on this. The following just creates a separate table with two columns in it. class User extends EntityBase { ... /** * @ORM\ManyToMany(targetEntity="AppBundle\Entity\House") */ protected $action; Basically, what I want to achieve is: in the user_house table the

Dependency injection with custom Doctrine 2 data type

本小妞迷上赌 提交于 2021-02-15 06:19:19
问题 I have pretty much an identical issue as Dependency injection with custom Doctrine 2 hydrator, but I need to inject a service into a custom data type , not into a hydrator. The solution in the referenced question is relies on duplicating and modifying doctrine source code as Doctrine initializes the classes itself. Hopefully another approach is viable to custom data types? This is for a Symfony3 application, if there could be some magic to be applied there. 回答1: Per the comments in the

Dependency injection with custom Doctrine 2 data type

試著忘記壹切 提交于 2021-02-15 06:15:56
问题 I have pretty much an identical issue as Dependency injection with custom Doctrine 2 hydrator, but I need to inject a service into a custom data type , not into a hydrator. The solution in the referenced question is relies on duplicating and modifying doctrine source code as Doctrine initializes the classes itself. Hopefully another approach is viable to custom data types? This is for a Symfony3 application, if there could be some magic to be applied there. 回答1: Per the comments in the

Dependency injection with custom Doctrine 2 data type

六眼飞鱼酱① 提交于 2021-02-15 06:15:54
问题 I have pretty much an identical issue as Dependency injection with custom Doctrine 2 hydrator, but I need to inject a service into a custom data type , not into a hydrator. The solution in the referenced question is relies on duplicating and modifying doctrine source code as Doctrine initializes the classes itself. Hopefully another approach is viable to custom data types? This is for a Symfony3 application, if there could be some magic to be applied there. 回答1: Per the comments in the

Doctrine Query Language, Two joins query [closed]

送分小仙女□ 提交于 2021-02-11 13:41:31
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . Improve this question I have a problem with dql. I can't write properly query. Need to rewrite the query to dql 'SELECT Movie.title, Movie.price, Order.order_data, Order.order_status FROM (Order LEFT JOIN Order_has_Movie ON Order.order_id = Order_has_Movie.order_id) INNER JOIN Movie ON Order_has

Doctrine 2, count when left join

一个人想着一个人 提交于 2021-02-11 12:24:28
问题 I have this: ->select('COUNT(x)')->setMaxResults(null)->setFirstResult(0)->getQuery()->getSingleScalarResult(); this works as long as I dont have join. If I have left join, it will also count the duplicated left-columns. How to prevent that? 回答1: You can do that by grouping: $qb->select('COUNT(x)') ->leftJoin('x.another_table', 'a') ->groupBy('x.id') ->setMaxResults(null) ->setFirstResult(0) ->getQuery() ->getSingleScalarResult(); 来源: https://stackoverflow.com/questions/36296138/doctrine-2

Doing a WHERE .. IN subquery in Doctrine 2

允我心安 提交于 2021-02-11 05:53:14
问题 I'd like to select order items from all orders with a specific item. In SQL I'd do it like this: SELECT DISTINCT i.id, i.name, order.name FROM items i JOIN orders o ON i.order_id=o.id WHERE o.id IN ( SELECT o2.id FROM orders o2 JOIN items i2 ON i2.order_id=o2.id AND i2.id=5 ) AND i.id != 5 ORDER BY o.orderdate DESC LIMIT 10 How would I do this query with the query builder? 回答1: This is how I would try it: /** @var Doctrine\ORM\EntityManager $em */ $expr = $em->getExpressionBuilder(); $em-

Add a new column in Doctrine 2 in Zend Framework

拈花ヽ惹草 提交于 2021-02-08 09:28:20
问题 I have Zend framework script with doctrine 2. I need to add a new column, what is the correct chronology to go about doing that i.e create column, update entities, run migration etc. Any help appreciated. 回答1: If you want manually then create a column in database table and specify that column in you entity class as bellow /** * @ORM\Column(type="string") // if column is varchar */ protected $title; if you have already set a CLI for generate entity and database schema file Then use this -- add