相关疑难解决方法(0)

覆盖Doctrine 2继承中的inversedBy映射

我有以下实体:

class Restaurant
{
    /**
     * @OneToMany(targetEntity="CollectionTime", mappedBy="restaurant")
     */
    protected $collectionTimes;

    /**
     * @OneToMany(targetEntity="DeliveryTime", mappedBy="restaurant")
     */
    protected $deliveryTimes;
}
Run Code Online (Sandbox Code Playgroud)

映射到同一实体的两个子类:

/**
 * @Entity
 * @InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorMap({
 *   "CollectionTime" = "CollectionTime",
 *   "DeliveryTime"   = "DeliveryTime"
 * })
 */
abstract class OrderTime
{
    /**
     * @ManyToOne(targetEntity="Restaurant")
     */
    protected $restaurant;
}

/**
 * @Entity
 */
class CollectionTime extends OrderTime
{
}

/**
 * @Entity
 */
class DeliveryTime extends OrderTime
{
}
Run Code Online (Sandbox Code Playgroud)

现在的问题是,doctrine orm:validate-schema报告以下错误:

  • 字段Restaurant#collectionTimes位于双向关系的反面,但目标实体CollectionTime#restaurant上指定的mappedBy关联不包含所需的'inversedBy = collectionTimes'属性.

  • 字段Restaurant#deliveryTimes位于双向关系的反面,但目标实体DeliveryTime#restaurant上指定的mappedBy关联不包含所需的'inversedBy = deliveryTimes'属性.

简而言之,Doctrine希望每个 …

doctrine-orm

10
推荐指数
2
解决办法
2676
查看次数

标签 统计

doctrine-orm ×1