2
私人性质,而阅读Doctrine documentation,我发现这个例子:查询父的原则
/**
* @Entity
* @InheritanceType("SINGLE_TABLE")
* @DiscriminatorColumn(name="discr", type="string")
* @DiscriminatorMap({"person" = "Person", "employee" = "Employee"})
*/
class Person
{
/**
* @Id @Column(type="integer")
* @GeneratedValue
*/
protected $id;
/**
* @Column(type="string", length=50)
*/
protected $name;
}
/**
* @Entity
*/
class Employee extends Person
{
/**
* @Column(type="string", length=50)
*/
private $department;
}
根据该文档时,Employee
类可以查询这样:
SELECT e FROM Entities\Employee e WHERE e.name = 'test';
我的问题是:如果Person
和Employee
都具有name
属性,具有不同的范围和值,那该怎么办?例如:
class Person {
private $name;
}
class Employee extends Person {
private $name;
}
我的猜测是,这个查询将针对Employee::$name
跑:
SELECT e FROM Entities\Employee e WHERE e.name = 'test';
是否有可能的话,对查询Person::$name
,但仍只返回Employee实例?喜欢的东西:
SELECT e FROM Entities\Employee e WHERE e.parent.name = 'test';
谢谢,确实是有道理的DQL这样! – Benjamin
对于任何感兴趣的人,这实际上记录在[这里](http://www.doctrine-project.org/docs/orm/2.1/en/reference/architecture.html):“类层次结构中的任何两个实体类从彼此直接或间接继承必须不具有相同名称的映射属性,也就是说,如果B从A继承,则B必须不具有与从A继承的已映射字段具有相同名称的映射字段。 – Benjamin