Doctrine 1
  1. Doctrine 1
  2. DC-882

Doctrine Collection FromArray doesn't adhere to KeyColumn

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.3
    • Fix Version/s: None
    • Component/s: Record
    • Labels:
      None

      Description

      Using the following in the base class:

      $this->setAttribute(Doctrine_Core::ATTR_COLL_KEY, 'class');

      Then executing a query to array the indexes of the entity are not that of the class field:

      example:

      array(
       0 => ..
       1 => ...
      );
      

      fix:

      /**
           * Populate a Doctrine_Collection from an array of data
           *
           * @param string $array 
           * @return void
           */
          public function fromArray($array, $deep = true)
          {
              $data = array();
              foreach ($array as $rowKey => $row) {
                  $this[$rowKey]->fromArray($row, $deep);
              }
          }
      

      to

      /**
           * Populate a Doctrine_Collection from an array of data
           *
           * @param string $array 
           * @return void
           */
          public function fromArray($array, $deep = true)
          {
              $data = array();
              $keyColumn = $this->keyColumn;
              foreach ($array as $rowKey => $row) {
                  $rowKey = $keyColumn AND isset($row[$keyColumn]) ? $row[$keyColumn] : $rowKey;
                  $this[$rowKey]->fromArray($row, $deep);
              }
          }
      

        Activity

        There are no comments yet on this issue.

          People

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

            Dates

            • Created:
              Updated: