Skip to content

Commit

Permalink
Merge pull request #3627 from rchavik/3.0-associations-remove-all
Browse files Browse the repository at this point in the history
ORM\Associations: Add removeAll() method
  • Loading branch information
markstory committed Jun 3, 2014
2 parents 6f3a1c4 + 74db983 commit 2273621
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/ORM/Associations.php
Expand Up @@ -122,6 +122,19 @@ public function remove($alias) {
unset($this->_items[strtolower($alias)]);
}

/**
* Remove all registered associations.
*
* Once removed associations will not longer be reachable
*
* @return void
*/
public function removeAll() {
foreach ($this->_items as $alias => $object) {
$this->remove($alias);
}
}

/**
* Save all the associations that are parents of the given entity.
*
Expand Down
17 changes: 17 additions & 0 deletions tests/TestCase/ORM/AssociationsTest.php
Expand Up @@ -63,6 +63,23 @@ public function testAddHasRemoveAndGet() {
$this->assertNull($this->associations->get('Users'));
}

/**
* Test removeAll method
*
* @return void
*/
public function testRemoveAll() {
$this->assertEmpty($this->associations->keys());

$belongsTo = new BelongsTo([]);
$this->assertSame($belongsTo, $this->associations->add('Users', $belongsTo));
$belongsToMany = new BelongsToMany([]);
$this->assertSame($belongsToMany, $this->associations->add('Cart', $belongsToMany));

$this->associations->removeAll();
$this->assertEmpty($this->associations->keys());
}

/**
* Test getting associations by property.
*
Expand Down

0 comments on commit 2273621

Please sign in to comment.