【发布时间】:2019-05-08 14:51:01
【问题描述】:
我有 2 张 XXXX 和 YYYY 两张表。在第一个中,我有一个指向第二个的外键。
create table XXXXXX
(
id int not null,
yyyyy_id int not null,
)
create table YYYYY
(
id int not null,
)
所以在我的 Doctrine Entity 中,我想用 Doctrine Annotation 来表示这种关系。但是,所有关联(OneToMany、ManyToOne、...)都需要 targetEntity 参数。
是否可以有一个像$yyyyId 这样的自定义字段并对其进行映射?
可能是这样的:
/**
* @ORM\Column(name="yyyyy_id", type="integer")
* @ORM\@JoinTable(
* name="YYYYY",
* joinColumns={@ORM\JoinColumn(name="yyyyy_id", referencedColumnName="id", fieldName="yyyyyId")}
* )
*/
private $yyyyyId;
并且有一个等价于:
alter table XXXXX
add constraint fk foreign key (yyyyy_id) references YYYYY (id) on delete cascade;
【问题讨论】:
-
听起来您正在尝试使用 JoinTable 进行 OneToMany,此处的文档:doctrine-project.org/projects/doctrine-orm/en/2.6/reference/…
标签: symfony doctrine-orm doctrine