Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1318

Unexpectet behavior while using ManyToOne as part ofr composite key

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Incomplete
    • Affects Version/s: 2.1
    • Fix Version/s: None
    • Component/s: Mapping Drivers
    • Security Level: All
    • Labels:
      None
    • Environment:
      ubuntu 64x

      Description

      Hi!

      Ran into a problem while wanted to use a ManyToOne as part of a primary key:

       * @Entity
       * @Table(name="user_preferences")
        */
      class UserPreferences  {
      
          /**
           * @Id
           * @ManyToOne(targetEntity="User",cascade={"persist"})
           *  @JoinColumn(name="user_id", referencedColumnName="id")
           */
          protected $user;
          /**
           * @Id
           * @GeneratedValue(strategy="NONE")
           * @Column(name="preference_id",type="smallint",nullable=false)
           */
          protected $preference_id;
      

      By default doctrine creates a table with 2 single keys (the preference key is the primary key) which is of course incorrect.
      Had to add @Column(name="user_id",type="integer") to the user column to fix the index problem but that introduced another problem. The entity no longer accepter \Entity\User as a value for user and takes only a smallint as defined.

        Activity

        Peter Jasiulewicz created issue -
        Benjamin Eberlei made changes -
        Field Original Value New Value
        Description Hi!

        Ran into a problem while wanted to use a ManyToOne as part of a primary key:

         
         * @Entity
         * @Table(name="user_preferences")
          */
        class UserPreferences {

            /**
             * @Id
             * @ManyToOne(targetEntity="User",cascade={"persist"})
             * @JoinColumn(name="user_id", referencedColumnName="id")
             */
            protected $user;
            /**
             * @Id
             * @GeneratedValue(strategy="NONE")
             * @Column(name="preference_id",type="smallint",nullable=false)
             */
            protected $preference_id;


        By default doctrine creates a table with 2 single keys (the preference key is the primary key) which is of course incorrect.
        Had to add @Column(name="user_id",type="integer") to the user column to fix the index problem but that introduced another problem. The entity no longer accepter \Entity\User as a value for user and takes only a smallint as defined.
        Hi!

        Ran into a problem while wanted to use a ManyToOne as part of a primary key:

         {code}
         * @Entity
         * @Table(name="user_preferences")
          */
        class UserPreferences {

            /**
             * @Id
             * @ManyToOne(targetEntity="User",cascade={"persist"})
             * @JoinColumn(name="user_id", referencedColumnName="id")
             */
            protected $user;
            /**
             * @Id
             * @GeneratedValue(strategy="NONE")
             * @Column(name="preference_id",type="smallint",nullable=false)
             */
            protected $preference_id;
        {code}

        By default doctrine creates a table with 2 single keys (the preference key is the primary key) which is of course incorrect.
        Had to add @Column(name="user_id",type="integer") to the user column to fix the index problem but that introduced another problem. The entity no longer accepter \Entity\User as a value for user and takes only a smallint as defined.
        Benjamin Eberlei made changes -
        Workflow jira [ 12898 ] jira-feedback [ 13956 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback [ 13956 ] jira-feedback2 [ 15820 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 15820 ] jira-feedback3 [ 18076 ]
        Benjamin Eberlei made changes -
        Status Open [ 1 ] Awaiting Feedback [ 10000 ]
        made changes -
        Status Awaiting Feedback [ 10000 ] In Progress [ 3 ]
        Marco Pivetta made changes -
        Status In Progress [ 3 ] Awaiting Feedback [ 10000 ]
        Benjamin Eberlei made changes -
        Status Awaiting Feedback [ 10000 ] Open [ 1 ]
        Benjamin Eberlei made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Incomplete [ 4 ]

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Peter Jasiulewicz
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: