Go to Google Groups Home    doctrine-user
Problem inserting circular object references

scott <sc...@danielfamily.com>

We have a fairly classic User, Group, and GroupHasUser kind of schema
with a couple of small twists. The User owns a group and the Group
owns a user (the author of the group). You can see a stripped down
version of the schema below.

The plan was for a newly constructed User object to configure the
group that it owned. The result is that the User contains a Group
object and the Group object contains a GroupHasUser object with the
original User a member of the Group (thus the circular reference).

Saving the User results in the Group being inserted and then Doctrine
tries to make the GroupHasUser without creating the User first. The
result is an error. What it needs to do is create the Group, then
create the User, and finally the GroupHasUser.

It there some way to make this happen in the right order?

Thanks,

Scott

[schema]
Groups:
  columns:
    id:
      type: integer(4)
      primary: true
      autoincrement: true
    group_name:
      type: string(64)
    author_id: integer(4)
  relations:
    Author:
      class: User
      local: author_id
      foreign: id
      type: one
    Users:
      class: User
      local: group_id
      foreign: user_id
      refClass: GroupHasUser
User:
  columns:
    id:
      type: integer(4)
      primary: true
      autoincrement: true
    user_name:
      type: string(50)
      notnull: true
    friend_group_id: integer(4)
  relations:
    Groups:
      local: user_id
      foreign: group_id
      refClass: GroupHasUser
    FriendGroup:
      class: FriendGroup
      local: friend_group_id
      foreign: id
      type: one
FriendGroup:
      inheritance:
        extends: Groups
        type: column_aggregation
        keyField: type
        keyValue: 1
GroupHasUser:
  columns:
    id:
      type: integer(4)
      primary: true
      autoincrement: true
    user_id:
      type: integer(4)
      notnull: true
    group_id:
      type: integer(4)
      notnull: true
  relations:
    User:
      local: user_id
      foreign: id
      type: one
    Group:
      class: Groups
      local: group_id
      foreign: id
      type: one