我有实体派对。不久它看起来像这样:
AppBundle\Entity\Main\Party:
type: entity
table: main.party
id:
id:
type: integer
nullable: false
id: true
generator:
strategy: IDENTITY
fields:
legalName:
type: string
nullable: false
length: 255
options:
fixed: false
column: legal_name
manyToMany:
partiesForPartner:
targetEntity: AppBundle\Entity\Main\Party
mappedBy: partnersForParty
fetch: EXTRA_LAZY
cache:
usage: NONSTRICT_READ_WRITE
partnersForParty:
cascade: ["all"]
targetEntity: AppBundle\Entity\Main\Party
inversedBy: partiesForPartner
fetch: LAZY
joinTable:
name: main.party_partnership
joinColumns:
party_id:
referencedColumnName: id
inverseJoinColumns:
partner_id:
referencedColumnName: id
还有一个实体 PartyPartnership 。其中包括一些额外的道具。
AppBundle\Entity\Main\PartyPartnership:
type: entity
repositoryClass: AppBundle\Repository\Main\PartyPartnershipRepository
table: main.party_partnership
uniqueConstraints:
party_partnership_ukey:
columns:
- party_id
- partner_id
id:
id:
type: integer
nullable: false
options:
unsigned: false
id: true
generator:
strategy: IDENTITY
fields:
codePartyByPartner:
type: string
nullable: true
length: 35
options:
fixed: false
column: code_party_by_partner
codePartnerByParty:
type: string
nullable: true
length: 35
options:
fixed: false
column: code_partner_by_party
manyToOne:
party:
targetEntity: AppBundle\Entity\Main\Party
cascade: { }
fetch: LAZY
mappedBy: null
inversedBy: null
joinColumns:
party_id:
referencedColumnName: id
orphanRemoval: false
partner:
targetEntity: AppBundle\Entity\Main\Party
cascade: { }
fetch: LAZY
mappedBy: null
inversedBy: null
joinColumns:
partner_id:
referencedColumnName: id
orphanRemoval: false
lifecycleCallbacks: { }
除了 Party 中的多对多关联外,所有这些映射都是从DB导入的。现在,当我尝试启动doctrine命令时,例如'doctrine:schema:validate'或'doctrine:schema:update'。我收到错误'名称'main.party_partnership'表已经存在。'
答案 0 :(得分:1)
Symfony ManyToMany在链接的两个实体之间创建一个表。
这意味着它会在main.party_partnership
和party
之间自动创建表partnership
。
Party ---(ManyToMany main.party_partnership)---> Partnership
您只需要引用oneToMany
,然后移除manyToMany
Party ---(OneToMany)---> PartyPartnership
Partnership ---(OneToMany)---> PartyPartnership
答案 1 :(得分:0)
几个小时后对我有用的东西:清除缓存。