[英]Symfony&Doctrine2: Value of `mappedBy` annotation?
I am learning Symfony 3 with Doctrine 2. 我正在使用教义2学习Symfony 3。
When I have OneToMany
relationship in Doctrine entity, what exactly I have to put into mappedBy
annotation? 当我在Doctrine实体中具有OneToMany
关系时,我到底要在mappedBy
注释中放什么呢?
Imagine this simple example: 想象一下这个简单的例子:
<?php
namespace AppBundle\Entity;
/**
* @ORM\Entity
* @ORM\Table(name="blog_category")
*/
class Category
{
// ...
/**
* @ORM\OneToMany(targetEntity="Article", mappedBy="category")
*/
private $articles;
// ...
}
Why is the "category" correct value for mappedBy
? 为什么“类别”的正确值是mappedBy
? Why isn't it "blog_category" or "Category" (uppercase "C")? 为什么不是“ blog_category”或“ Category” (大写的“ C”)? Or "AppBundle:Category" ? 还是“ AppBundle:类别” ?
To give a complement, almost everything you could do in doctrine (could surely be applied for any other ORM/ODM), in almost every contexts (QueryBuilder, findBy methods, ...) you'll use property names rather than column names. 作为补充,几乎在理论上您可以做的所有事情(肯定可以应用于任何其他ORM / ODM),在几乎每种情况下(QueryBuilder,findBy方法...),您都将使用属性名称而不是列名称。
The reason is quite simple, an ORM deals with objects and their properties, abstracting the real tables and their columns, no matter of the database engine or anything else. 原因很简单,无论数据库引擎是什么,ORM都会处理对象及其属性,抽象出真实的表及其列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.