我的学说实体映射存在问题。 有一个基本的用户实体,我想创建一个朋友实体,由两个外键到用户表,友谊的第一个所有者和另一个。 我尝试以这种方式(yaml),以正确的方式生成实体,但是当我使用doctrine方案更新创建数据库时,它的结果完全不同。
用户实体:
..\..\Entity\User:
type: entity
uniqueConstraints:
usernameCanonical:
columns: usernameCanonical
emailCanonical:
columns: emailCanonical
oneToMany:
owners:
targetEntity: Friend
mappedBy: owner
friends:
targetEntity: Friend
mappedBy: friend
朋友实体:
..\..\Entity\Friend:
type: entity
table: friend
lifecycleCallbacks:
prePersist: [setCreated, setModified]
preUpdate: [setModified]
manyToOne:
owner:
targetEntity: User
inversedBy: friends
joinColumn:
name: user
referencedColumnName: id
onDelete: cascade
friend:
targetEntity: User
inversedBy: owners
joinColumn:
name: user
referencedColumnName: id
onDelete: cascade
这应该创建两个从朋友到用户的外来,但是它创建一个像:
ALTER TABLE friend ADD CONSTRAINT FK_55EEAC618D93D649 FOREIGN KEY (user) REFERENCES users (id) ON DELETE CASCADEe