简体   繁体   English

不同于注释Symfony 2 / Doctrine 2

[英]Different in Annotation Symfony 2 / Doctrine 2

What is the difference between these two? 这两者有什么区别?

/**
* @ORM\ManyToOne(targetEntity="Category", inversedBy="products",cascade={"remove"})
* @ORM\JoinColumn(name="category_id", referencedColumnName="id") 
*/
protected $category;

and

/**
 *
 * @ORM\ManyToOne(targetEntity="Category", inversedBy="products")
 * @ORM\JoinColumn(name="category_id", referencedColumnName="id", onDelete="CASCADE"))
 */
protected $category;

Thanks ! 谢谢 !

The first tells the ORM to perform itself the cascade. 第一个告诉ORM自己执行级联。 Hence Doctrine will keep data in memory to perform itself the delete cascade. 因此,Doctrine会将数据保存在内存中以执行删除级联。

The second will tell to the database to perform the onDelete cascade, unloading the process from doctrine. 第二个将告诉数据库执行onDelete级联,从doctrine卸载进程。

Remember that the first option will keep in memory the arrays / associations to perform the delete cascade, which can be really heavy. 请记住,第一个选项将在内存中保留数组/关联以执行删除级联,这可能非常繁重。

Typical use case for the first parameter is a case where your data model graph isn't too heavy, and you really want to benfit every entity lifecycle events, even those who are removed using the cascade. 第一个参数的典型用例是您的数据模型图不是太重,并且您真的想要适应每个实体生命周期事件,甚至是那些使用级联删除的事件。

The downside of the second is that you can't benfit these entity lifecycle events, but if your data model / graph is really too heavy, this can be the only option to deal with cascade. 第二个问题的缺点是你无法适应这些实体生命周期事件,但如果你的数据模型/图形真的太重,那么这可能是处理级联的唯一选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Symfony&Doctrine2:“ mappedBy”注释的值? - Symfony&Doctrine2: Value of `mappedBy` annotation? 如何在Symfony中继承自定义Doctrine类注释? - How to inherit custom Doctrine class annotation in Symfony? Symfony学说:向现有阅读器添加新的新注释名称空间 - Symfony Doctrine: Adding new new Annotation namespaces to an existing reader [Doctrine] [Symfony]在单个注释请求中进行多个联接(可能吗?) - [Doctrine][Symfony] Multiple Joins in a single annotation request (is it possible ?) Symfony2 doctrine2插入记录[语义错误]注释 - Symfony2 doctrine2 insert record [Semantical Error] The annotation 如何仅将一个文件用作Symfony 2中的Doctrine注释阅读器缓存? - How to use just one file as Doctrine annotation reader cache in Symfony 2? Gymle注释不能与Symfony2项目中的Doctrine2注释解析器一起使用 - Guzzle annotations not working with Doctrine2 annotation parser in Symfony2 project Symfony2学说NestedTree不同的实体类型 - Symfony2 Doctrine NestedTree different Entity Types 与Symfony 1.4,Doctrine有点不同 - A little different left join with Symfony 1.4, Doctrine Symfony2 Doctrine2 - 通过doctrine:mapping:import从现有数据库生成多对多注释 - Symfony2 Doctrine2 - generate Many-To-Many annotation from existing database by doctrine:mapping:import
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM