doctrine

Doctrine2 ORM select for update

拥有回忆 提交于 2019-12-18 03:12:49
问题 Please could you suggest me some approach how to implement SELECT FOR UPDATE with Doctrine? I need to read some counter value, use it in PHP code and immediately increment the value before someone else (from another process) uses the same value. 回答1: Locking support Doctrine 2 implements Locking support for entities: <?php use Doctrine\DBAL\LockMode; use Doctrine\ORM\OptimisticLockException; $theEntityId = 1; $expectedVersion = 184; try { $entity = $em->find('User', $theEntityId, LockMode:

Doctrine2 ORM select for update

谁说胖子不能爱 提交于 2019-12-18 03:12:10
问题 Please could you suggest me some approach how to implement SELECT FOR UPDATE with Doctrine? I need to read some counter value, use it in PHP code and immediately increment the value before someone else (from another process) uses the same value. 回答1: Locking support Doctrine 2 implements Locking support for entities: <?php use Doctrine\DBAL\LockMode; use Doctrine\ORM\OptimisticLockException; $theEntityId = 1; $expectedVersion = 184; try { $entity = $em->find('User', $theEntityId, LockMode:

Symfony 4 and Doctrine, how to generate repository automatically after mapping?

假装没事ソ 提交于 2019-12-18 02:43:55
问题 All the tutorials I am finding have the repository created automatically using make:entity when creating new tables but I have been importing from an existing database following the official documentation with the following command: php bin/console doctrine:mapping:import App\\Entity annotation --path=src/Entity This command does not seem to create any repository... and the documentation does not talk about generating a repository I know I can create one manually but is there a command to

Symfony 4 and Doctrine, how to generate repository automatically after mapping?

一世执手 提交于 2019-12-18 02:43:24
问题 All the tutorials I am finding have the repository created automatically using make:entity when creating new tables but I have been importing from an existing database following the official documentation with the following command: php bin/console doctrine:mapping:import App\\Entity annotation --path=src/Entity This command does not seem to create any repository... and the documentation does not talk about generating a repository I know I can create one manually but is there a command to

Importing tables from external database in Symfony2 with doctrine

∥☆過路亽.° 提交于 2019-12-17 22:30:35
问题 I have a Symfony2 project with its own database, and now I want to connect to another database (another project) so I can modify some tables. I created the new connection in config_dev.yml doctrine: dbal: default_connection: default connections: default: driver: pdo_mysql host: localhost dbname: database1 user: root password: buv: driver: pdo_mysql host: localhost dbname: database2 user: root password: I tried to import the schema with the following command: $ php app/console doctrine:mapping

Get the last insert id with doctrine 2?

帅比萌擦擦* 提交于 2019-12-17 22:12:09
问题 How can I get the last insert id with doctrine 2 ORM? I didn't find this in the documentation of doctrine, is this even possible? 回答1: I had to use this after the flush to get the last insert id: $em->persist($user); $em->flush(); $user->getId(); 回答2: You can access the id after calling the persist method of the entity manager. $widgetEntity = new WidgetEntity(); $entityManager->persist($widgetEntity); $entityManager->flush(); $widgetEntity->getId(); You do need to flush in order to get this

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

How does Doctrine 2 retrieve entities without calling the entity's constructor?

我是研究僧i 提交于 2019-12-17 19:15:07
问题 Does anyone know how this works? 回答1: This works by unserializing objects. Unserializing in PHP does prevent the constructor to be called as the serialized object has been already constructed. Create an object without calling it's constructor in PHP: $className = 'stdClass'; # set classname here $serialized = sprintf('O:%d:"%s":0:{}', strlen($className), $className); $object = unserialize($serialized); For more details please see this article: Doctrine 2: Give me my constructor back 来源: https

How to define current timestamp in yaml with doctrine?

不羁岁月 提交于 2019-12-17 18:51:56
问题 I tried the following yaml code: columns: created_time: type: timestamp notnull: true default: default CURRENT_TIMESTAMP In the outputted sql statement, the field is treated as datetime instead of timestamp, which I cannot define the current timestamp in it... If I insist to use timestamp to store current time, how to do so in yaml? 回答1: You could use the 'Timestampable' functionality in doctrine, eg: actAs: Timestampable: created: name: created_time updated: disabled: true columns: created

Doctrine 2 WHERE IN clause using a collection of entities

大憨熊 提交于 2019-12-17 18:47:25
问题 I'm attempting to build a query in Doctrine 2 that finds all Vacancy entities which are related to any of the given VacancyWorkingHours entities. The Vacancy entity looks as follows: /** * Vacancy * * @ORM\Table(name="vacancy") * @ORM\Entity(repositoryClass="JaikDean\CareersBundle\Entity\VacancyRepository") */ class Vacancy { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var VacancyWorkingHours * * @ORM