教义固定装置 - 循环引用 [英] Doctrine fixtures - circular references
问题描述
有没有办法加载具有循环引用的夹具?例如,我有以下夹具:
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]
如您所见,Nicole_Team 引用了 Nicole...但 Nicole 也引用了 Nicole_Team.
As you can see, Nicole_Team references Nicole... but Nicole also references Nicole_Team.
当 Manager 不是必需的列时,这没问题(已加载夹具,但 Manager 为 NULL),但现在它是必需的,无法加载夹具.
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.
推荐答案
这个怎么样:
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.
这篇关于教义固定装置 - 循环引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!