We are working on a symfony/doctrine project and have come to a near halt on
development.
We feel that now, it may be a bug/feature in doctrine, regarding foreign
keys

Part of our model includes a join table that references three different
table. Below is a diagram of what the model looks like, and the relevant
portion of our schema.yml is at the bottom.

http://imgur.com/dfFYI.png

We have a form that contains a set of embedded forms that attempt to create
a new Person entry and add rows to the join table, adding items to the
PersonName table as needed.

The form attempts to do this by creating and saving PersonName objects with
NameType parameters, but are running into the problem of Doctrine not
including that column when trying to do an insert into the join table.

Part of the problem seems to be caused by the
Doctrine_Connection_UnitOfWork::saveAssociations method:

                foreach ($v->getInsertDiff() as $r) {
                    $assocRecord = $assocTable->create();

 $assocRecord->set($assocTable->getFieldName($rel->getForeign()), $r);

 $assocRecord->set($assocTable->getFieldName($rel->getLocal()), $record);
                    $this->saveGraph($assocRecord);
                }

Are we correct in understanding that this means that Doctrine 1.2 does not
support tables with multiple foreign keys in this scenario?


Here is the relevant portion of schema.yml:

agPerson:
  columns:
    id:
      primary: true
      type: integer(5)
      autoincrement: true
  relations:
    agPersonName:
      class: agPersonName
      refClass: agPersonMjAgPersonName
      local: person_id
      foreign: person_name_id
    agPersonNameType:
      class: agPersonNameType
      refClass: agPersonMjAgPersonName
      local: person_id
      foreign: person_name_type_id
agPersonNameType:
  columns:
    id:
      primary: true
      type: integer(2)
      autoincrement: true
    person_name_type:
      unique: true
      type: string(30)
      notnull: true
    app_display:
      default: 1
      type: boolean
      notnull: true
  relations:
    agPerson:
      class: agPerson
      refClass: agPersonMjAgPersonName
      local: person_name_type_id
      foreign: person_id
    agPersonName:
      class: agPersonName
      refClass: agPersonMjAgPersonName
      local: person_name_type_id
      foreign: person_name_id
agPersonName:
  columns:
    id:
      primary: true
      type: integer(5)
      autoincrement: true
    person_name:
      unique: true
      type: string(64)
      notnull: true
  relations:
    agPerson:
      class: agPerson
      refClass: agPersonMjAgPersonName
      local: person_name_id
      foreign: person_id
    agPersonNameType:
      class: agPersonNameType
      refClass: agPersonMjAgPersonName
      local: person_name_id
      foreign: person_name_type_id
agPersonMjAgPersonName:
  columns:
    id:
      primary: true
      type: integer(5)
      autoincrement: true
    person_id:
      type: integer(5)
      notnull: true
    person_name_id:
      type: integer(5)
      notnull: true
    person_name_type_id:
      type: integer(2)
      notnull: true
    is_primary:
      type: boolean
      notnull: true
  indexes:
    UX_ag_person_mj_ag_person_name:
      fields: [person_name_id, person_name_type_id, person_id]
      type: unique
  relations:
    agPerson:
      local: person_id
      foreign: id
    agPersonName:
      local: person_name_id
      foreign: id
    agPersonNameType:
      local: person_name_type_id
      foreign: id
actAs:
  Timestampable:



As a caveat: we've noticed that sfdoctrineguard group table, has such a
relationship:

mysql> describe sf_guard_user_group;
+------------+----------+------+-----+---------+-------+
| Field      | Type     | Null | Key | Default | Extra |
+------------+----------+------+-----+---------+-------+
| user_id    | int(11)  | NO   | PRI | 0       |       |
| group_id   | int(11)  | NO   | PRI | 0       |       |
| created_at | datetime | NO   |     | NULL    |       |
| updated_at | datetime | NO   |     | NULL    |       |
+------------+----------+------+-----+---------+-------+


i.e. IT has two foreign keys taken into account

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to