我正在尝试在第三方捆绑包中的实体中添加属性。这是我的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');
}
答案 0 :(得分:0)
根据@Rvanlaak的建议:
PHP继承在Doctrine中不起作用,只要它们不使用超类或相关映射。特别是一旦配置格式(yml,annotation,xml)混合,这将是艰难的,所以最简单的是覆盖整个实体。另请参阅:http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/inheritance-mapping.html
我最终通过将整个orm文件复制到我的自定义捆绑包中并修改它来添加我的自定义字段和关联来解决此问题。