doctrine

Doctrine 2 LifecycleCallbacks with abstract base class are not called

核能气质少年 提交于 2019-12-28 05:52:08
问题 I have this situation: Abstract Class: abstract class AbstractBase { /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") * @var integer */ protected $id; /** * @ORM\Column(type="datetime", name="updated_at") * @var \DateTime $updatedAt */ protected $updatedAt; /** * @ORM\PreUpdate */ public function setUpdatedAt() { die('THIS POINT IS NEVER REACHED'); $this->updatedAt = new \DateTime(); } } Concrete Class: /** * @ORM\Entity(repositoryClass="Entity\Repository\UserRepository") *

Doctrine 2 LifecycleCallbacks with abstract base class are not called

巧了我就是萌 提交于 2019-12-28 05:52:07
问题 I have this situation: Abstract Class: abstract class AbstractBase { /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") * @var integer */ protected $id; /** * @ORM\Column(type="datetime", name="updated_at") * @var \DateTime $updatedAt */ protected $updatedAt; /** * @ORM\PreUpdate */ public function setUpdatedAt() { die('THIS POINT IS NEVER REACHED'); $this->updatedAt = new \DateTime(); } } Concrete Class: /** * @ORM\Entity(repositoryClass="Entity\Repository\UserRepository") *

Is there a built-in way to get all of the changed/updated fields in a Doctrine 2 entity

為{幸葍}努か 提交于 2019-12-27 11:00:10
问题 Let's suppose I retrieve an entity $e and modify its state with setters: $e->setFoo('a'); $e->setBar('b'); Is there any possibility to retrieve an array of fields that have been changed? In case of my example I'd like to retrieve foo => a, bar => b as a result PS: yes, I know I can modify all the accessors and implement this feature manually, but I'm looking for some handy way of doing this 回答1: You can use Doctrine\ORM\EntityManager#getUnitOfWork to get a Doctrine\ORM\UnitOfWork . Then just

Is there a built-in way to get all of the changed/updated fields in a Doctrine 2 entity

假如想象 提交于 2019-12-27 11:00:06
问题 Let's suppose I retrieve an entity $e and modify its state with setters: $e->setFoo('a'); $e->setBar('b'); Is there any possibility to retrieve an array of fields that have been changed? In case of my example I'd like to retrieve foo => a, bar => b as a result PS: yes, I know I can modify all the accessors and implement this feature manually, but I'm looking for some handy way of doing this 回答1: You can use Doctrine\ORM\EntityManager#getUnitOfWork to get a Doctrine\ORM\UnitOfWork . Then just

Symfony2 中Doctrine2

孤街浪徒 提交于 2019-12-26 20:13:12
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> ###symfony2 中 根据 doctrine的entity 生成数据表 php app/console doctrine:schema:update 这行并不会真正执行,只是计算下需要执行多少条sql语句 php app/console doctrine:schema:update --dump-sql 将要执行的sql语句打印到命令行 php app/console doctrine:schema:update --force 执行,这才是真正的执行 ###Symfony2 Doctrine从现有Database生成Entity 生成元数据 php app/console doctrine:mapping:import --force SiteHomeBundle xml 生成Entity php app/console doctrine:mapping:convert annotation ./src 生成getter setter php app/console doctrine:generate:entities SiteHomeBundle --no-backup ###Symfony2 Doctrine 其他实用 doctrine:generate:crud

What’s most efficient way to query a LEFT JOIN with tons of data with Doctrine 2 DQL

走远了吗. 提交于 2019-12-25 18:43:29
问题 I have an entity “coin” linked with a oneToMany on prices. Prices is updated every minute and has millions of entries. What I’m trying to achieve is a DQL query that will grab the last price to date. Right now I see 2 ways to do it and I’m wondering which one is best in term of performance: I could look for prices in the DB with ‘prices’.’lastupdated’ equal to the last update. OR I could grab the last 100 price ids (we update 100 coins every minute and add 100 new rows in the Database) with a

doctrine/symfony 4 - avoid duplicate entry when persisting child entities

Deadly 提交于 2019-12-25 18:17:53
问题 I have the following setup: I parse an api response that has a structure similar to this (I oversimplify a bit): { orders: [ { // some data customers: [ { // some data addresses: [ { id: 436456445 // some data }, // Other addresses ] } ] }, { customers: [ { addresses: [ { id: 436456445 // some data } ] } ] } ] } Note that a specific address appears twice in the response (same id). I deep travel (hope is the right translation) the structure and make entities. All goes well until the save part

Warning: spl_object_hash() expects parameter 1 to be object

自古美人都是妖i 提交于 2019-12-25 17:19:07
问题 Warning: spl_object_hash() expects parameter 1 to be object, string given in /var/www/sitetwo/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 1367 I created MainBlogBundle with Category.php and Product.php using yml mapping annotation via php app/console commands. After using CRUD actions for add/edit/delete/show actions I tried to add a category and after submitting Add category form I get the Warning: spl_object_hash() expects parameter 1 to be object, string given in /var/www

How to handle related null-objects correctly in symfony 1.4

半腔热情 提交于 2019-12-25 16:25:18
问题 The situation is that I have doctrine entity classes Category and Item with the following YAML definitions: Category: columns: parent_category_id: { type: integer } name: { type: string(255), notnull: true, notblank: true } items_count: { type: integer, notnull: true, default: 0 } relations: ParentCategory: { class: Category, local: parent_category_id, foreign: id } Item: columns: category_id: { type: integer, notnull: true } name: { type: string(255), notnull: true, notblank: true }

How to handle related null-objects correctly in symfony 1.4

半世苍凉 提交于 2019-12-25 16:25:15
问题 The situation is that I have doctrine entity classes Category and Item with the following YAML definitions: Category: columns: parent_category_id: { type: integer } name: { type: string(255), notnull: true, notblank: true } items_count: { type: integer, notnull: true, default: 0 } relations: ParentCategory: { class: Category, local: parent_category_id, foreign: id } Item: columns: category_id: { type: integer, notnull: true } name: { type: string(255), notnull: true, notblank: true }