Doctrine fixtures - circular references

别来无恙 提交于 2020-02-01 04:15:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!