Reputation: 1580
I'm trying to make a relation one to many as follows.
I have a UserProfile Entity, that have some private fields, and it have 2 fields that are another entities:
Initially, I only did a onetoMany relation, because a want that a userProfile has an array of musical tastes and another array of artists.
Well, those are the entities I have right now:
UserProfile:
myDomain\Entity\UserProfile:
type: entity
table: null
repositoryClass: MyMelomanBundle\Repository\UserProfileRepository
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: myDomain\Entity\MusicalTaste
mappedBy: musicalTaste
joinColumn:
name: musicalTaste_id
referencedColumnName: id
favouriteArtist:
targetEntity: myDomain\Entity\FavouriteArtist
mappedBy: favouriteArtist
joinColumn:
name: favouriteArtist_id
referencedColumnName: id
lifecycleCallbacks: { }
MusicalTaste:
myDomain\Entity\MusicalTaste:
type: entity
table: musical_taste
repositoryClass: MyMelomanBundle\Repository\MusicalTasteRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
name:
type: string
length: 255
nullable: true
column: name
manyToOne:
userProfile:
targetEntity: myDomain\Entity\UserProfile
inversedBy: musicalTaste
joinColumn:
name: userProfile_id
referencedColumName: id
lifecycleCallbacks: { }
FavouriteArtists:
myDomain\Entity\FavouriteArtist:
type: entity
table: favourite_artist
repositoryClass: MyMelomanBundle\Repository\FavouriteArtistRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
name:
type: string
length: 255
nullable: true
column: name
manyToOne:
userProfile:
targetEntity: myDomain\Entity\UserProfile
inversedBy: favouriteArtist
joinColumn:
name: userProfile_id
referencedColumName: id
When i'm updating the doctrine schema, all looks good, aparently, but if I do:
I have to create a manyToOne relation on MusicalTaste and Favourite Artists? (Prevously I did but no relations were created...) But there is some fails when validating:
$ php bin/console doctrine:schema:validate
[Mapping] FAIL - The entity-class 'myDomain\Entity\FavouriteArtist' mapping is invalid:
* The mappings myDomain\Entity\FavouriteArtist#userProfile and myDomain\Entity\UserProfile#favouriteArtist are inconsistent with each other.
[Mapping] FAIL - The entity-class 'myDomain\Entity\MusicalTaste' mapping is invalid:
* The mappings myDomain\Entity\MusicalTaste#userProfile and myDomain\Entity\UserProfile#musicalTaste are inconsistent with each other.
[Mapping] FAIL - The entity-class 'myDomain\Entity\UserProfile' mapping is invalid:
* The association myDomain\Entity\UserProfile#musicalTaste refers to the owning side field myDomain\Entity\MusicalTaste#musicalTaste which does not exist.
* The association myDomain\Entity\UserProfile#favouriteArtist refers to the owning side field myDomain\Entity\FavouriteArtist#favouriteArtist which does not exist
How I can fix them? Thanks in advance
Upvotes: 1
Views: 83
Reputation: 1580
As Mehmet said:
Change "mappedBy: musicalTaste" as "mappedBy: userProfile" in userprofile.yml worked perfectly.
Upvotes: 1