Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-383

Setting Column name doesn't work predictably in associations

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Invalid
    • Affects Version/s: 2.0-ALPHA4
    • Fix Version/s: 2.0-BETA4
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      Setting a column name that is different from the property name yields errors in associations (e.g. in a one to one association I get "Undefined index: shipping_id in /var/www/wetawa/library/Doctrine/ORM/UnitOfWork.php on line 1782 Call ")

      ...
          /**
           * @Column(type="bigint", name="shipping_id")
           *
           * @var integer
           */
          protected $shippingId=0;
          /**
           * @OneToOne(targetEntity="Shipping")
           * @JoinColumn(name="shipping_id", referencedColumnName="id")
           * 
           * @var Shipping
           */
          protected $shipping;
      

      The only way I've been able to get associations to work is by using the default naming so $shipping_id instead of $shippingId

        Activity

        Hide
        Roman S. Borschel added a comment -

        Whenever you have questions on how to do something properly without dedicated foreign key properties just drop a mail to the user mailing list. For most cases there is a good solution and if not, we will create one.

        Show
        Roman S. Borschel added a comment - Whenever you have questions on how to do something properly without dedicated foreign key properties just drop a mail to the user mailing list. For most cases there is a good solution and if not, we will create one.
        Hide
        Benjamin Eberlei added a comment -

        This is not an issue. Closed

        Show
        Benjamin Eberlei added a comment - This is not an issue. Closed
        Hide
        Aigars Gedroics added a comment - - edited

        Still there is another issue related to this one.

        When I create yaml files from existing database using the command line command "orm:convert-mapping --from-database yaml" the relational field "target_id" is created in both places - as a field and in the relation definition (under oneToOne in my case). Here I get the same problem as described above and the target object cannot be retrieved.

        Sample generated yaml for city—country relation:

        City:
          type: entity
          table: city
          fields:
            id:
              id: true
              type: integer
              unsigned: false
              nullable: false
              generator:
                strategy: IDENTITY
            countryId:
              type: string(2)
              fixed: true
              nullable: false
              column: country_id
            name:
              type: string(255)
              fixed: false
              nullable: true
          oneToOne:
            country:
              targetEntity: Country
              cascade: {  }
              mappedBy: null
              joinColumns:
                country_id:
                  referencedColumnName: id
              orphanRemoval: false
          lifecycleCallbacks: {  }
        

        This yaml causes problems when city is loaded.

        Is it a bug or is it just me?

        Show
        Aigars Gedroics added a comment - - edited Still there is another issue related to this one. When I create yaml files from existing database using the command line command "orm:convert-mapping --from-database yaml" the relational field "target_id" is created in both places - as a field and in the relation definition (under oneToOne in my case). Here I get the same problem as described above and the target object cannot be retrieved. Sample generated yaml for city—country relation: City: type: entity table: city fields: id: id: true type: integer unsigned: false nullable: false generator: strategy: IDENTITY countryId: type: string(2) fixed: true nullable: false column: country_id name: type: string(255) fixed: false nullable: true oneToOne: country: targetEntity: Country cascade: { } mappedBy: null joinColumns: country_id: referencedColumnName: id orphanRemoval: false lifecycleCallbacks: { } This yaml causes problems when city is loaded. Is it a bug or is it just me?
        Hide
        Aigars Gedroics added a comment -

        The file attached is modified YAML export driver which workarounds the problem with the problem described in the previous comment.

        Also it can append namespace to classes in the YAML files generated from the database schema.

        Hope it helps someone.

        Show
        Aigars Gedroics added a comment - The file attached is modified YAML export driver which workarounds the problem with the problem described in the previous comment. Also it can append namespace to classes in the YAML files generated from the database schema. Hope it helps someone.
        Hide
        Roman S. Borschel added a comment -

        This should be fixed now.

        Show
        Roman S. Borschel added a comment - This should be fixed now.

          People

          • Assignee:
            Roman S. Borschel
            Reporter:
            akeem philbert
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: