From 8f478629d1c255a4e854ae69bd815180941fe6fa Mon Sep 17 00:00:00 2001 From: Mikulas Date: Fri, 23 Oct 2015 22:45:37 +0200 Subject: [PATCH] entity: fix setReadOnlyValue on IPropertyContainer [closes #130] --- src/Relationships/OneHasMany.php | 4 +- .../Entity/entity.setReadOnlyValue().phpt | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 tests/cases/integration/Entity/entity.setReadOnlyValue().phpt diff --git a/src/Relationships/OneHasMany.php b/src/Relationships/OneHasMany.php index cb074093..ad251bd6 100644 --- a/src/Relationships/OneHasMany.php +++ b/src/Relationships/OneHasMany.php @@ -55,7 +55,7 @@ protected function createCollection() protected function updateRelationshipAdd(IEntity $entity) { $this->updatingReverseRelationship = TRUE; - $entity->setValue($this->metadata->relationship->property, $this->parent); + $entity->getProperty($this->metadata->relationship->property)->setInjectedValue($this->parent); $this->updatingReverseRelationship = FALSE; } @@ -63,7 +63,7 @@ protected function updateRelationshipAdd(IEntity $entity) protected function updateRelationshipRemove(IEntity $entity) { $this->updatingReverseRelationship = TRUE; - $entity->setValue($this->metadata->relationship->property, NULL); + $entity->getProperty($this->metadata->relationship->property)->setInjectedValue(NULL); $this->updatingReverseRelationship = FALSE; } diff --git a/tests/cases/integration/Entity/entity.setReadOnlyValue().phpt b/tests/cases/integration/Entity/entity.setReadOnlyValue().phpt new file mode 100644 index 00000000..cb17e7f7 --- /dev/null +++ b/tests/cases/integration/Entity/entity.setReadOnlyValue().phpt @@ -0,0 +1,41 @@ +orm->tags->getById(1); + $tagB = $this->orm->tags->getById(2); + + $follower = new TagFollower(); + $follower->tag = $tagA; + + $follower->getMetadata()->getProperty('tag')->isReadonly = TRUE; + + $follower->setReadOnlyValue('tag', $tagB); + + Assert::same($tagB, $follower->tag); + } + +} + + +$test = new EntitySetReadOnlyValueTest($dic); +$test->run();