问题
Is there any way to load fixtures that have circular referencing? As an example I have the following fixture:
BusinessEntityTeam:
Nicole_Team:
name: Nicole's Team
Manager: [Nicole]
Business: [ACMEWidgets]
sfGuardUser
Nicole:
first_name: Nicole
last_name: Jones
email_address: nicole@example.com
username: nicole
password: nicole
Groups: [Group_abc]
Team: [Nicole_Team]
As you can see, Nicole_Team references Nicole... but Nicole also references Nicole_Team.
When Manager wasn't a required column this was OK (the fixture loaded, but Manager was NULL), but now it's required it's impossible to load the fixture.
The only work-around I can see is to put the Team relation in its own object ('Profile' for example) so the relations are no longer circular.
Is there any other approach? Every user has to be in a team, but only a few users are team managers. I'm quite open to the fact that my data model may be badly designed and have room for improvement.
回答1:
How about this:
BusinessEntityTeam:
Nicole_Team:
name: Nicole's Team
Business: [ACMEWidgets]
sfGuardUser
Nicole:
first_name: Nicole
last_name: Jones
email_address: nicole@example.com
username: nicole
password: nicole
Groups: [Group_abc]
Team: [Nicole_Team]
ManagerFor: [Nicole_Team]
In order to avoid circular referencing, you have to put the relations in one model.
来源:https://stackoverflow.com/questions/3777993/doctrine-fixtures-circular-references