Skip to content

Commit

Permalink
Allow associations to be iterated
Browse files Browse the repository at this point in the history
Added an iterator to the class so that associations can be looped through
  • Loading branch information
davidyell committed Apr 28, 2015
1 parent 3d64adf commit 363af9e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/ORM/AssociationCollection.php
Expand Up @@ -14,19 +14,21 @@
*/
namespace Cake\ORM;

use ArrayIterator;
use Cake\ORM\Association;
use Cake\ORM\AssociationsNormalizerTrait;
use Cake\ORM\Entity;
use Cake\ORM\Table;
use InvalidArgumentException;
use IteratorAggregate;

/**
* A container/collection for association classes.
*
* Contains methods for managing associations, and
* ordering operations around saving and deleting.
*/
class AssociationCollection
class AssociationCollection implements IteratorAggregate
{

use AssociationsNormalizerTrait;
Expand Down Expand Up @@ -292,4 +294,14 @@ public function normalizeKeys($keys)

return $this->_normalizeAssociations($keys);
}

/**
* Allow looping through the associations
*
* @return \Cake\ORM\Association
*/
public function getIterator()
{
return new ArrayIterator($this->_items);
}
}

0 comments on commit 363af9e

Please sign in to comment.