Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Avoiding notice when unlinking values using HasMany
Fixes #8164
  • Loading branch information
lorenzo committed Mar 5, 2016
1 parent 88e1bb8 commit bc64a61
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ORM/Association/HasMany.php
Expand Up @@ -306,7 +306,8 @@ public function unlink(EntityInterface $sourceEntity, array $targetEntities, $op

$this->_unlink($foreignKey, $target, $conditions, $options);

if ($options['cleanProperty']) {
$result = $sourceEntity->get($property);
if ($options['cleanProperty'] && $result !== null) {
$sourceEntity->set(
$property,
(new Collection($sourceEntity->get($property)))
Expand Down
18 changes: 18 additions & 0 deletions tests/TestCase/ORM/TableTest.php
Expand Up @@ -4126,6 +4126,24 @@ public function testUnlinkHasManyNotCleanProperty()
$this->assertFalse($author->dirty('articles'));
}

/**
* Integration test for unlinking entities with HasMany.
* Checking that no error happens when the hasMany property is originally
* null
*
* @return void
*/
public function testUnlinkHasManyEmpty()
{
$authors = TableRegistry::get('Authors');
$articles = TableRegistry::get('Articles');
$authors->hasMany('Articles');
$author = $authors->get(1);
$article = $authors->Articles->get(1);

$authors->Articles->unlink($author, [$article]);
}


/**
* Integration test for replacing entities which depend on their source entity with HasMany and failing transaction. False should be returned when
Expand Down

0 comments on commit bc64a61

Please sign in to comment.