gpt4 book ai didi

php - Symfony 中的 Doctrine\ORM\Mapping\MappingException

转载 作者:可可西里 更新时间:2023-11-01 08:39:22 26 4
gpt4 key购买 nike

我得到的完整错误是:

[Doctrine\ORM\Mapping\MappingException]                                       
Property "followed" in "BackendBundle\Entity\Following" was already declared, but it must be declared only once

当我尝试在我的 BackendBundle 中创建实体时。

我在 MYSQL 中有 3 个表“empresas”、“tecnicos”、“profesionistas”,下面是每个表的 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: { }

最佳答案

看起来您正在尝试为 3 个不同的实体声明 ManyToOne 关系。仅从语法上看,您应该重复 followed 三遍似乎是错误的。

我之前遇到过类似的问题,我希望一个实体使用相同的属性映射到 X 个不同的实体。像这样:

$人->$车辆

其中 $vehicle 可以是 Bicycle、Car 或 Skateboard 的实例(抱歉,我正在为我的例子苦苦挣扎)。

我认为使用学说是不可能的,您可能需要在两者之间添加另一个实体(例如 $person->$vehicleOwnership->$vehicle)或使用 doctrine inheritance

关于php - Symfony 中的 Doctrine\ORM\Mapping\MappingException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42234720/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com