Doctrine 1
  1. Doctrine 1
  2. DC-562

Broken OneToOne Relationship on two Primary Keys

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Invalid
    • Affects Version/s: 1.2.1
    • Fix Version/s: None
    • Component/s: Data Fixtures
    • Labels:
      None
    • Environment:
      Doctrine 1.2.1
      MySQL 5.1.37

      Description

      Hi,
      if you have a One-To-One Relationship which uses Primary Keys on both ends Doctrine screws up the relationship if you import the data from a data fixture.

      Example:

      DB contents:

      User:
      id|username|password
      1|eins|eins
      2|zwei|zwei
      3||drei|drei
      4|vier|vier

      Contact:
      id|name
      1|eins
      3|drei

      Contact:
      id|name
      2|zwei
      4|vier

      {{
      //schema.yml
      User:
      columns:
      id:
      primary: true
      autoincrement: true
      type: integer(4)
      username: string(255)
      password: string(255)
      relations:
      Contact:
      local: id
      foreign: id
      foreignType: one

      Contact:
      columns:
      id:
      type: integer(4)
      primary: true
      autoincrement: true
      name:
      type: string(255)

      Contact2:
      columns:
      id:
      type: integer(4)
      primary: true
      autoincrement: true
      name:
      type: string(255)
      }}

      ./doctrine dump-data

      {{
      //data/fixtures/data.yml
      Contact:
      Contact_1:
      name: eins
      Contact_3:
      name: drei
      Contact2:
      Contact2_2:
      name: zwei
      Contact2_4:
      name: vier
      User:
      User_1:
      username: eins
      password: eins
      User_2:
      username: zwei
      password: zwei
      User_3:
      username: drei
      password: drei
      User_4:
      username: vier
      password: vier
      }}

      ./doctrine build-all-reload

      DB contents:

      User:
      id|username|password
      1|eins|eins
      2|zwei|zwei
      3||drei|drei
      4|vier|vier

      Contact:
      id|name
      1|eins
      2|drei

      Contact:
      id|name
      1|zwei
      2|vier

      Now the relations are broken.

        Activity

        Hide
        Jonathan H. Wage added a comment -

        Your ticket is hard to read, just for future reference it would be wise to make sure the issue is readable for us. Anyways, I had a look and your schema is incorrect. You have a foreign key but it is also set as primary and auto increment.

        Show
        Jonathan H. Wage added a comment - Your ticket is hard to read, just for future reference it would be wise to make sure the issue is readable for us. Anyways, I had a look and your schema is incorrect. You have a foreign key but it is also set as primary and auto increment.
        Hide
        Ulf Thomas added a comment -

        Sorry for the unreadable ticket, I tryed to make it understadable as much as I can.

        The thing with the foreign key and primary key is that we have a existing database and want to port it to Doctrine.
        In the database the structure is like that and in the documentation I didn't see anything that say that this won't work. Can you point me to some aditional information?

        Show
        Ulf Thomas added a comment - Sorry for the unreadable ticket, I tryed to make it understadable as much as I can. The thing with the foreign key and primary key is that we have a existing database and want to port it to Doctrine. In the database the structure is like that and in the documentation I didn't see anything that say that this won't work. Can you point me to some aditional information?
        Hide
        Shirley Chan added a comment -

        I'm working on an open source application, Sahana Agasti (http://sahanafoundation.org/), using Symfony 1.4 as the framework and Doctrine as the ORM. This project stumble into a similar issue with establishing a direct 1:1 relationships on primary keys. Below is an example of a person and person's date of birth table. In the yml file, Person has an id field as the primary key. This field is referenced by the primary key field person_id in PersonDateOfBirth. However, Doctrine only creates the tables and not the relationship between the two tables correctly.

        schema.yml
        agPerson:
        columns:
        id:
        primary: true
        type: integer(5)
        autoincrement: true
        notnull: true
        relations:
        agPersonDateOfBirth:
        type: one
        local: id
        foreign: person_id
        agPersonDateOfBirth:
        columns:
        person_id:
        primary: true
        type: integer(5)
        notnull: true
        date_of_birth:
        type: date
        notnull: true
        relations:
        agPerson:
        foreignType: one
        type: one
        local: person_id
        foreign: id

        schema.sql
        CREATE TABLE ag_person (id BIGINT AUTO_INCREMENT, PRIMARY KEY(id)) ENGINE = INNODB;
        CREATE TABLE ag_person_date_of_birth (person_id BIGINT, date_of_birth DATE NOT NULL, PRIMARY KEY(person_id)) ENGINE = INNODB;

        Show
        Shirley Chan added a comment - I'm working on an open source application, Sahana Agasti ( http://sahanafoundation.org/ ), using Symfony 1.4 as the framework and Doctrine as the ORM. This project stumble into a similar issue with establishing a direct 1:1 relationships on primary keys. Below is an example of a person and person's date of birth table. In the yml file, Person has an id field as the primary key. This field is referenced by the primary key field person_id in PersonDateOfBirth. However, Doctrine only creates the tables and not the relationship between the two tables correctly. schema.yml agPerson: columns: id: primary: true type: integer(5) autoincrement: true notnull: true relations: agPersonDateOfBirth: type: one local: id foreign: person_id agPersonDateOfBirth: columns: person_id: primary: true type: integer(5) notnull: true date_of_birth: type: date notnull: true relations: agPerson: foreignType: one type: one local: person_id foreign: id schema.sql CREATE TABLE ag_person (id BIGINT AUTO_INCREMENT, PRIMARY KEY(id)) ENGINE = INNODB; CREATE TABLE ag_person_date_of_birth (person_id BIGINT, date_of_birth DATE NOT NULL, PRIMARY KEY(person_id)) ENGINE = INNODB;

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Ulf Thomas
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: