@AssociationOverride和@AttributeOverride在新的Doctrine 2.3中 [英] @AssociationOverride and @AttributeOverride in new Doctrine 2.3

查看:329
本文介绍了@AssociationOverride和@AttributeOverride在新的Doctrine 2.3中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据标题,新注释的目的是 @AssociationOverride @AttributeOverride

As per title, what's the purpose of the new annotation @AssociationOverride and @AttributeOverride?

我在Doctrine网站上唯一可以找到的是:

The only thing I can find on Doctrine website is:


@AssociationOverride和@AttributeOverride对于特征和
MappedSuperclass有用)

@AssociationOverride and @AttributeOverride (useful for Trait and MappedSuperclass)


推荐答案

通过查看提交,我们可以看到它用于覆盖已经在映射中定义的字段映射超级类/特征。

By looking at the code in the commit, we can see that it is used to override a field mapping already defined in a mapped superclass / trait.

提交中包含的测试表明此行为:

The tests included in the commit demonstrate this behaviour:

/** 
 * @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



Subclass using @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

的子类

Subclass using @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
{
    ...
}

这篇关于@AssociationOverride和@AttributeOverride在新的Doctrine 2.3中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆