我得到的完整错误是:
[Doctrine\ORM\Mapping\MappingException]
Property "followed" in "BackendBundle\Entity\Following" was already declared, but it must be declared only once
当我试图在我的BackendBundle制作实体时。
我在MYSQL“empresas”,“tecnicos”,“profesionistas”有3张桌子,后面有每张桌子的fk
CREATE TABLE following(
id int(255) not null auto_increment,
user int(255),
followed int(255),
CONSTRAINT pk_following PRIMARY KEY(id),
CONSTRAINT fk_empresas_following FOREIGN KEY(user) REFERENCES empresas(id),
CONSTRAINT fk_tecnicos_following FOREIGN KEY(user) REFERENCES tecnicos(id),
CONSTRAINT fk_profesionistas_following FOREIGN KEY(user) REFERENCES profesionistas(id),
CONSTRAINT fk_empresas_followed FOREIGN KEY(followed) REFERENCES empresas(id),
CONSTRAINT fk_tecnicos_followed FOREIGN KEY(followed) REFERENCES tecnicos(id),
CONSTRAINT fk_profesionistas_followed FOREIGN KEY(followed) REFERENCES profesionistas(id)
)ENGINE = InnoDb;
BackendBundle\Entity\Following
的代码是
BackendBundle\Entity\Following:
type: entity
table: following
indexes:
fk_following_empresas:
columns:
- user
fk_following_tecnicos:
columns:
- user
fk_following_empresas:
columns:
- user
fk_followed_empresas:
columns:
- followed
fk_followed_tecnicos:
columns:
- followed
fk_followed_profesionistas:
columns:
- followed
id:
id:
type: integer
nullable: false
options:
unsigned: false
id: true
generator:
strategy: IDENTITY
manyToOne:
followed:
targetEntity: Empresa
cascade: { }
fetch: LAZY
mappedBy: null
inversedBy: null
joinColumns:
followed:
referencedColumnName: id
orphanRemoval: false
followed:
targetEntity: Tecnico
cascade: { }
fetch: LAZY
mappedBy: null
inversedBy: null
joinColumns:
followed:
referencedColumnName: id
orphanRemoval: false
followed:
targetEntity: Profesionista
cascade: { }
fetch: LAZY
mappedBy: null
inversedBy: null
joinColumns:
followed:
referencedColumnName: id
orphanRemoval: false
user:
targetEntity: Empresa
cascade: { }
fetch: LAZY
mappedBy: null
inversedBy: null
joinColumns:
user:
referencedColumnName: id
orphanRemoval: false
user:
targetEntity: Tecnico
cascade: { }
fetch: LAZY
mappedBy: null
inversedBy: null
joinColumns:
user:
referencedColumnName: id
orphanRemoval: false
user:
targetEntity: Profesionista
cascade: { }
fetch: LAZY
mappedBy: null
inversedBy: null
joinColumns:
user:
referencedColumnName: id
orphanRemoval: false
lifecycleCallbacks: { }
答案 0 :(得分:1)
看起来您正在尝试为3个不同的实体声明ManyToOne关系。仅从语法上看,你应该重复followed
三次是错误的。
在我希望实体使用相同属性映射到X个不同实体之前,我遇到了类似的问题。像这样:
$人 - > $车辆
其中$ vehicle可以是Bicycle,Car或Skateboard的一个实例(对不起,我在这里努力争取我的榜样)。
我认为这不可能使用原则,您可能需要在两者之间添加另一个实体(例如$ person-> $ vehicleOwnership-> $ vehicle)或使用doctrine inheritance