根据标题,新注释 @AssociationOverride 和 @AttributeOverride 的目的是什么?
在Doctrine网站上,我唯一能找到的信息是:
@AssociationOverride 和 @AttributeOverride(对Trait和MappedSuperclass有用)
在Doctrine网站上,我唯一能找到的信息是:
@AssociationOverride 和 @AttributeOverride(对Trait和MappedSuperclass有用)
/**
* @MappedSuperclass
*/
class User
{
/**
* @Id
* @GeneratedValue
* @Column(type="integer", name="user_id", length=150)
*/
protected $id;
/**
* @Column(name="user_name", nullable=true, unique=false, length=250)
*/
protected $name;
/**
* @var ArrayCollection
*
* @ManyToMany(targetEntity="Group", inversedBy="users", cascade={"persist", "merge", "detach"})
* @JoinTable(name="users_groups",
* joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="group_id", referencedColumnName="id")}
* )
*/
protected $groups;
/**
* @var Address
*
* @ManyToOne(targetEntity="Address", cascade={"persist", "merge"})
* @JoinColumn(name="address_id", referencedColumnName="id")
*/
protected $address;
...
}
@AssociationOverride
进行子类化/*
* @Entity
* @AssociationOverrides({
* @AssociationOverride(name="groups",
* joinTable=@JoinTable(
* name="users_admingroups",
* joinColumns=@JoinColumn(name="adminuser_id"),
* inverseJoinColumns=@JoinColumn(name="admingroup_id")
* )
* ),
* @AssociationOverride(name="address",
* joinColumns=@JoinColumn(
* name="adminaddress_id", referencedColumnName="id"
* )
* )
* })
*/
class Admin extends User
{
...
}
@AttributeOverride
进行子类化/**
* @Entity
* @AttributeOverrides({
* @AttributeOverride(name="id",
* column=@Column(
* name = "guest_id",
* type = "integer",
* length = 140
* )
* ),
* @AttributeOverride(name="name",
* column=@Column(
* name = "guest_name",
* nullable = false,
* unique = true,
* length = 240
* )
* )
* })
*/
class Guest extends User
{
...
}
guest_id
vsuser_id
,adminaddress_id
vsaddress_id
)。 - BenMorel