Skip to content
Permalink
Browse files

Avoiding notice when unlinking values using HasMany

Fixes #8164
  • Loading branch information...
lorenzo committed Mar 5, 2016
1 parent 88e1bb8 commit bc64a614b5c19262c98cf3f385e0e071e6b1382d
Showing with 20 additions and 1 deletion.
  1. +2 −1 src/ORM/Association/HasMany.php
  2. +18 −0 tests/TestCase/ORM/TableTest.php
@@ -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)))
@@ -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

0 comments on commit bc64a61

Please sign in to comment.
You can’t perform that action at this time.