0

分为三类:

  • A 类是抽象的,并且MappedSuperClass
  • B类继承自A
  • C类继承自B

PHP-wise 这很好用。还生成gettersetter使用php app/console doctrine:generate:entities App作品。

问题

使用创建模式时出现问题php app/console doctrine:schema:update --force。创建了 B 类和 C 类的表。抽象类的所有列都可用,B 和 C 类的专用字段也可用。

只有该列createdBy未在表 C 中生成。它丢失了。它是为表 B 创建的。问题出在哪里?

抽象A类

/**
 * @ORM\MappedSuperclass
 */
abstract class A {
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    protected $id;

    /**
     * @ORM\Column(type="string")
     */
    protected $name;

    /**
     * @Gedmo\Blameable(on="create")
     * @ORM\ManyToOne(targetEntity="AppBundle[…]")
     * @ORM\JoinColumn(name="created_by", referencedColumnName="id", nullable=false)
     */
    protected $createdBy;
}

B类

/**
 * @ORM\Entity
 * @ORM\Table(name="b")
 * @ORM\HasLifecycleCallbacks()
 */
class B extends A {
    /**
     * @ORM\Column(type="string")
     */
    protected $b;
}

C类

/**
 * @ORM\Entity
 * @ORM\Table(name="c")
 * @ORM\HasLifecycleCallbacks()
 */
class C extends B {
    /**
     * @ORM\Column(type="string")
     */
    protected $c;
}

注意:我清除了chaches,使用:

app/console cache:clear
app/console doctrine:cache:clear-metadata 
app/console doctrine:cache:clear-query  
app/console doctrine:cache:clear-result 
4

0 回答 0