我试图建立一个关系,如下所示。
我有一个用户配置文件实体,它有一些私有字段,它有 2 个字段是另一个实体:
- 音乐品味:ID和名称
- 收藏艺术家:ID 和姓名。
最初,我只做了一个一对一的关系,因为希望用户配置文件具有一系列音乐品味和另一组艺术家。
好吧,这些是我现在拥有的实体:
用户配置文件:
myDomainEntityUserProfile:
type: entity
table: null
repositoryClass: MyMelomanBundleRepositoryUserProfileRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
aboutMe:
type: string
length: 255
nullable: true
column: about_me
image:
type: string
length: 255
nullable: true
birthDate:
type: datetime
column: birth_date
nullable: true
oneToMany:
musicalTaste:
targetEntity: myDomainEntityMusicalTaste
mappedBy: musicalTaste
joinColumn:
name: musicalTaste_id
referencedColumnName: id
favouriteArtist:
targetEntity: myDomainEntityFavouriteArtist
mappedBy: favouriteArtist
joinColumn:
name: favouriteArtist_id
referencedColumnName: id
lifecycleCallbacks: { }
音乐品味:
myDomainEntityMusicalTaste:
type: entity
table: musical_taste
repositoryClass: MyMelomanBundleRepositoryMusicalTasteRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
name:
type: string
length: 255
nullable: true
column: name
manyToOne:
userProfile:
targetEntity: myDomainEntityUserProfile
inversedBy: musicalTaste
joinColumn:
name: userProfile_id
referencedColumName: id
lifecycleCallbacks: { }
最喜爱的艺术家:
myDomainEntityFavouriteArtist:
type: entity
table: favourite_artist
repositoryClass: MyMelomanBundleRepositoryFavouriteArtistRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
name:
type: string
length: 255
nullable: true
column: name
manyToOne:
userProfile:
targetEntity: myDomainEntityUserProfile
inversedBy: favouriteArtist
joinColumn:
name: userProfile_id
referencedColumName: id
当我更新教义图式时,一切看起来都不错,但如果我这样做:
我必须在音乐品味和最喜欢的艺术家上创建一个多ToOne关系?(以前我做了,但没有建立关系...但是验证时有一些失败:
$ PHP bin/console 原则:模式:验证
[Mapping] FAIL - The entity-class 'myDomainEntityFavouriteArtist' mapping is invalid:
* The mappings myDomainEntityFavouriteArtist#userProfile and myDomainEntityUserProfile#favouriteArtist are inconsistent with each other.
[Mapping] FAIL - The entity-class 'myDomainEntityMusicalTaste' mapping is invalid:
* The mappings myDomainEntityMusicalTaste#userProfile and myDomainEntityUserProfile#musicalTaste are inconsistent with each other.
[Mapping] FAIL - The entity-class 'myDomainEntityUserProfile' mapping is invalid:
* The association myDomainEntityUserProfile#musicalTaste refers to the owning side field myDomainEntityMusicalTaste#musicalTaste which does not exist.
* The association myDomainEntityUserProfile#favouriteArtist refers to the owning side field myDomainEntityFavouriteArtist#favouriteArtist which does not exist
我该如何修复它们?提前致谢
正如穆罕默德所说:
在userprofile.yml中将"mappedBy:musicalTaste"更改为"mappedBy:userProfile",效果很好。