Details

    • Type: New Feature New Feature
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-ALPHA3
    • Fix Version/s: 2.1
    • Component/s: None
    • Security Level: All
    • Labels:
      None

      Description

      Sometimes, a @ManyToOne field has to be the Primary Key, or part of the Primary Key. Adding @Id to the @ManyToOne does not help, an additional property with duplicates the referenced id is needed:

      (userId and User field in the Phonenumber class - to be able to set @Id on userId):
      http://pastebin.com/d51e021e2

      Allowing @Id on @ManyToOne fields (which would make the JoinColumn a PK) would help here. Any maybe this would also fix DDC-116

      1. ddc117_20100815.patch
        29 kB
        Benjamin Eberlei
      2. ddc117-20101228.diff
        28 kB
        Benjamin Eberlei
      3. ddc117test_cascade_persist.patch
        1 kB
        s9e

        Issue Links

          Activity

          Hide
          Benjamin Eberlei added a comment -

          @S9e: Yes this is obvious, it works only with Sequence as ID Generation strategy (for example with PostgreSQL)

          The problem is, during persist MySQL and SQLite don't know the value of the primary key yet. However for the @id + @ManyToOne patch to work it is necessary that all the dependencies primary keys are already known. That is why two step flush procedures are sometimes necessary.

          1. persist non fk+pk entities and flush them
          2. persist fk+pk entities then flush them

          Show
          Benjamin Eberlei added a comment - @S9e: Yes this is obvious, it works only with Sequence as ID Generation strategy (for example with PostgreSQL) The problem is, during persist MySQL and SQLite don't know the value of the primary key yet. However for the @id + @ManyToOne patch to work it is necessary that all the dependencies primary keys are already known. That is why two step flush procedures are sometimes necessary. 1. persist non fk+pk entities and flush them 2. persist fk+pk entities then flush them
          Hide
          Benjamin Eberlei added a comment -

          Patch is now finished and will be merged into master tomorrow.

          Show
          Benjamin Eberlei added a comment - Patch is now finished and will be merged into master tomorrow.
          Hide
          Benjamin Eberlei added a comment -

          Merged into master and scheduled for 2.1.

          Please test this patch extensively, there are tons of examples in tests/Doctrine/Tests/Models/DDC117 and tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php

          Show
          Benjamin Eberlei added a comment - Merged into master and scheduled for 2.1. Please test this patch extensively, there are tons of examples in tests/Doctrine/Tests/Models/DDC117 and tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php
          Hide
          Henrik Bjornskov added a comment -

          @Benjamin

          I have created a OneToOne relation on a User -> Profile where the profile is specified as the inverse side so i can have user_id be the primary key. And it all works as expected except that when i create a new User (The Profile object is getting created in the user constructor) and persist it (the relation have cascade-all specified) i end up with the error "The given entity has no identity.". But if i persist the user without creating the profile inside it and fliush and then create a Profile object and persist and flush that it all work.

          It seems like it dosent know that the User should be saved first so that it have an id and then save the profile. Dont know if this is a bug or it is expected behavior.

          Show
          Henrik Bjornskov added a comment - @Benjamin I have created a OneToOne relation on a User -> Profile where the profile is specified as the inverse side so i can have user_id be the primary key. And it all works as expected except that when i create a new User (The Profile object is getting created in the user constructor) and persist it (the relation have cascade-all specified) i end up with the error "The given entity has no identity.". But if i persist the user without creating the profile inside it and fliush and then create a Profile object and persist and flush that it all work. It seems like it dosent know that the User should be saved first so that it have an id and then save the profile. Dont know if this is a bug or it is expected behavior.
          Hide
          Benjamin Eberlei added a comment -

          expected behavior, you are using the id generator "assigned" which means on persist the id has to be assigned. In your case it isnt, because the related object has not been assigned an id itself, thus failing.

          Show
          Benjamin Eberlei added a comment - expected behavior, you are using the id generator "assigned" which means on persist the id has to be assigned. In your case it isnt, because the related object has not been assigned an id itself, thus failing.

            People

            • Assignee:
              Benjamin Eberlei
              Reporter:
              Nico Kaiser
            • Votes:
              8 Vote for this issue
              Watchers:
              11 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: