Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:  [email protected]
    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.

like image 925
PeterB Avatar asked Nov 14 '22 07:11

PeterB


1 Answers

How about this:

BusinessEntityTeam:
  Nicole_Team:
    name: Nicole's Team
    Business: [ACMEWidgets]

sfGuardUser
  Nicole:
    first_name:     Nicole
    last_name:      Jones
    email_address:  [email protected]
    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.

like image 57
Peter Long Avatar answered Dec 04 '22 10:12

Peter Long