Uploaded image for project: 'Doctrine 2 - ORM'
  1. Doctrine 2 - ORM
  2. DDC-250

ArrayCollection Key Column @indexBy

    Details

    • Type: New Feature
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.1
    • Component/s: Mapping Drivers
    • Security Level: All
    • Labels:
      None

      Description

      To be honest I feel like I saw this mentioned somewhere, but after looking around I couldn't find it, so I'll just post this anyway.

      I'd like the ability to set a property as the associative key on ArrayCollections. This functionality could probably be done in a PostLoad by iterating over the objects, but it seems like ArrayCollection should be able to handle this functionality already, it's just a matter of modifying the mapper/parser.

      Example:

      /**
       * @Entity
       */
      class Object
      {
      //... $id column and anything else ...
          /**
           * @OneToMany(targetEntity="Param", mappedBy="object")
           */
          protected $params;
      //...
          public function getParam($name)
          {
               return $this->params[$name];
          }
      }
      
      /**
       * @Entity
       */
      class Param
      {
          /**
           * @ManyToOne(targetEntity="Object")
           * @JoinColumn(name="object_id", referencedColumnName="id", nullable="false")
           */
          protected $object;
          /**
           * @Column(type="string")
           */
          protected $name;
          /**
           * @Column(type="string")
           */
          protected $value;
      }
      

      If you were able to specify an ArrayCollection key column then you would be able to have functions like getParam without having to loop over the objects in the collection. Something like:

       @OneToMany(targetEntity="Param", mappedBy="object", collectionKey="name") 

        Issue Links

          Activity

          mridgway Michael Ridgway created issue -
          beberlei Benjamin Eberlei made changes -
          Field Original Value New Value
          Summary ArrayCollection Key Column ArrayCollection Key Column @indexBy
          Fix Version/s 2.1 [ 10022 ]
          beberlei Benjamin Eberlei made changes -
          Link This issue relates to DDC-213 [ DDC-213 ]
          beberlei Benjamin Eberlei made changes -
          Link This issue depends on DDC-1018 [ DDC-1018 ]
          beberlei Benjamin Eberlei made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Assignee Roman S. Borschel [ romanb ] Benjamin Eberlei [ beberlei ]
          Resolution Fixed [ 1 ]
          beberlei Benjamin Eberlei made changes -
          Workflow jira [ 10718 ] jira-feedback [ 14223 ]
          beberlei Benjamin Eberlei made changes -
          Workflow jira-feedback [ 14223 ] jira-feedback2 [ 16087 ]
          beberlei Benjamin Eberlei made changes -
          Workflow jira-feedback2 [ 16087 ] jira-feedback3 [ 18340 ]
          ocramius Marco Pivetta made changes -
          Link This issue is required for DDC-54 [ DDC-54 ]
          ocramius Marco Pivetta made changes -
          Link This issue is required for DDC-54 [ DDC-54 ]

            People

            • Assignee:
              beberlei Benjamin Eberlei
              Reporter:
              mridgway Michael Ridgway
            • Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: