0

我正在尝试在第三方包中的实体中添加属性。这是我的 yml 文件

Acme\Bundle\AppBundle\Entity\Group:
type: entity
table: pim_catalog_group_new
changeTrackingPolicy: DEFERRED_EXPLICIT 
fields:
    sortOrder:
        type: integer        
manyToOne:
    family:
        targetEntity: Pim\Component\Catalog\Model\FamilyInterface
        joinColumn:
            name: family_id
            referencedColumnName: id
            onDelete: 'SET NULL'

当我运行以下命令时

php app/console doctrine:migrations:diff

它给了我id, family_id, sortOrder, code和其他简单的字段,但不包括来自父类的关联字段。这是生成的迁移脚本(请注意,缺少父级的 oneToMany、manyToMany 关联字段):

    public function up(Schema $schema)
{
    // this up() migration is auto-generated, please modify it to your needs
    $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');

    $this->addSql('CREATE TABLE pim_catalog_group (id INT AUTO_INCREMENT NOT NULL, family_id INT DEFAULT NULL, code VARCHAR(100) NOT NULL, sortOrder INT NOT NULL, UNIQUE INDEX UNIQ_3196D4CB77153098 (code), INDEX IDX_3196D4CBC35E566A (family_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
    $this->addSql('ALTER TABLE pim_catalog_group ADD CONSTRAINT FK_3196D4CBC35E566A FOREIGN KEY (family_id) REFERENCES pim_catalog_family (id) ON DELETE SET NULL');
    $this->addSql('ALTER TABLE pim_catalog_group_translation DROP FOREIGN KEY FK_622D98DB7E366551');
    $this->addSql('ALTER TABLE pim_catalog_group_translation ADD CONSTRAINT FK_622D98DB7E366551 FOREIGN KEY (foreign_key) REFERENCES pim_catalog_group (id) ON DELETE CASCADE');
    $this->addSql('ALTER TABLE pim_catalog_association_group DROP FOREIGN KEY FK_E91414DDFE54D947');
    $this->addSql('ALTER TABLE pim_catalog_association_group ADD CONSTRAINT FK_E91414DDFE54D947 FOREIGN KEY (group_id) REFERENCES pim_catalog_group (id) ON DELETE CASCADE');
    $this->addSql('ALTER TABLE pim_catalog_group_product DROP FOREIGN KEY FK_7AC0C83AFE54D947');
    $this->addSql('ALTER TABLE pim_catalog_group_product ADD CONSTRAINT FK_7AC0C83AFE54D947 FOREIGN KEY (group_id) REFERENCES pim_catalog_group (id) ON DELETE CASCADE');
}
4

1 回答 1

0

根据@Rvanlaak 的建议:

PHP 继承在 Doctrine 中不起作用,只要它们没有使用超类或相关映射。尤其是一旦配置格式(yml、注解、xml)混合在一起,这将很困难,所以最简单的方法是覆盖整个实体。另请参阅:http ://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/inheritance-mapping.html

我最终通过将整个 orm 文件复制到我的自定义包中并修改它以添加我的自定义字段和关联来解决这个问题。

于 2016-11-18T16:47:10.033 回答