Changeset 5032

Show
Ignore:
Timestamp:
10/02/08 07:07:05 (3 months ago)
Author:
jwage
Message:

[1.1] fixes #1138 Added Doctrine_Collection::toKeyValueArray()

Location:
branches/1.1
Files:
1 added
3 modified

Legend:

Unmodified
Added
Removed
  • branches/1.1/lib/Doctrine/Collection.php

    r4957 r5032  
    684684 
    685685    /** 
     686     * Build an array made up of the values from the 2 specified columns 
     687     * 
     688     * @param string $key  
     689     * @param string $value  
     690     * @return array $result 
     691     */ 
     692    public function toKeyValueArray($key, $value) 
     693    { 
     694        $result = array(); 
     695        foreach ($this as $record) { 
     696            $result[$record->$key] = $record->$value; 
     697        } 
     698        return $result; 
     699    } 
     700 
     701    /** 
    686702     * Populate a Doctrine_Collection from an array of data 
    687703     * 
  • branches/1.1/tests/run.php

    r5030 r5032  
    132132$tickets->addTestCase(new Doctrine_Ticket_1326_TestCase()); 
    133133$tickets->addTestCase(new Doctrine_Ticket_1335_TestCase()); 
     134$tickets->addTestCase(new Doctrine_Ticket_1338_TestCase()); 
    134135$tickets->addTestCase(new Doctrine_Ticket_1351_TestCase()); 
    135136$tickets->addTestCase(new Doctrine_Ticket_1365_TestCase()); 
  • branches/1.1/UPGRADE_TO_1_1

    r5031 r5032  
    1313      ->where('u.id IN ?', array(1, 2, 3)); 
    1414    $users = $q->execute(); 
    15  
    16 [r5018](http://trac.doctrine-project.org/changeset/5018) - Added `Doctrine::ATTR_AUTO_FREE_QUERY_OBJECTS` for auto freeing query objects after execution  
    17  
    18     $manager->setAttribute('auto_free_query_objects'); 
    19     $q = Doctrine_Query::create() 
    20       ->from('User u') 
    21     $users = $q->execute(); // $q->free() is triggered 
    2215 
    2316[r5019](http://trac.doctrine-project.org/changeset/5019) - `unlink()` and `link()` have been changed to not delete references until `save()` is called on the object. Also, fixed synchronizeWithArray() to synchronize many to many relationships. 
     
    4336    $user->synchronizeWithArray($userArray); 
    4437    $user->save(); 
     38 
     39Default Options 
     40--------------- 
    4541 
    4642[r5027](http://trac.doctrine-project.org/changeset/5039) - Added support for setting default charset and collate for tables. 
     
    8682    $q->select(); 
    8783    $user = $q->fetchOne(); 
     84 
     85[r5018](http://trac.doctrine-project.org/changeset/5018) - Added `Doctrine::ATTR_AUTO_FREE_QUERY_OBJECTS` for auto freeing query objects after execution  
     86 
     87    $manager->setAttribute('auto_free_query_objects'); 
     88    $q = Doctrine_Query::create() 
     89      ->from('User u') 
     90    $users = $q->execute(); // $q->free() is triggered 
     91 
     92Doctrine Collection 
     93------------------- 
     94 
     95You can now convert a Doctrine_Collection in to a key value array made up of the values from the two specified columns. 
     96 
     97    $q = Doctrine_Query::create() 
     98        ->from('User u'); 
     99    $users = $q->execute(); 
     100 
     101    $array = $users->toKeyValueArray('id', 'name'); 
     102    print_r($array); 
     103 
     104    /* 
     105    array( 
     106      4 => 'zYne', 
     107      5 => 'Arnold Schwarzenegger', 
     108      6 => 'Michael Caine', 
     109      7 => 'Takeshi Kitano', 
     110      8 => 'Sylvester Stallone', 
     111      9 => 'Kurt Russell', 
     112      10 => 'Jean Reno', 
     113      11 => 'Edward Furlong', 
     114    ) 
     115    */