Skip to content

Commit

Permalink
repository: fixed non-cascade remove with empty non-nullable relation…
Browse files Browse the repository at this point in the history
…ship
  • Loading branch information
hrach committed Feb 11, 2016
1 parent 4bd3d98 commit 7030718
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Repository/RemovalHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ private static function setNulls($entity, array $metadata, IModel $model, array
}

} else {
if ($type === Relationship::ONE_HAS_MANY && $entity->getValue($name)->count() === 0) {
continue;
}

$entityClass = get_class($entity);
$reverseEntityClass = $propertyMeta->relationship->entity;
$primaryValue = $entity->getValue('id');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ class RelationshipOneHasManyRemoveTest extends DataTestCase
Assert::false($author->isPersisted());
}


public function testRemoveNoCascadeEmptyCollection()
{
$author = new Author();
$author->name = 'A';
$this->orm->authors->persistAndFlush($author);

$author->getMetadata()->getProperty('books')->relationship->cascade['remove'] = false;

$this->orm->authors->removeAndFlush($author);
Assert::false($author->isPersisted());
}
}


Expand Down

0 comments on commit 7030718

Please sign in to comment.