Permalink
Browse files

you can now save a different object in a HasOne relationship (fixes #1)

  • Loading branch information...
a-musing-moose committed Apr 26, 2011
1 parent 8d5b3b9 commit f577bfb7861b50d46f7efcf9e63a0d44e4708082
Showing with 27 additions and 1 deletion.
  1. +26 −0 integration-tests/TestHasOne.php
  2. +1 −1 src/Morph/Property/HasOne.php
@@ -47,4 +47,30 @@ public function testStoresParentAndChild()
}
+ public function testStoresReplacementChild()
+ {
+ $parent = new HasOneParent();
+ $parent->Name = 'Has One Parent';
+
+ $child = new Child();
+ $child->Name = 'Child';
+
+ $parent->Child = $child;
+
+ $parent->save();
+ $this->assertCollectionExists('HasOneParent');
+ $this->assertCollectionExists('Child');
+
+ $this->assertDocumentExists('HasOneParent', $parent->id());
+ $this->assertDocumentExists('Child', $child->id());
+
+ //now for the second child
+ $child2 = new Child();
+ $child2->Name = 'Child2';
+ $parent->Child = $child2;
+ $parent->save();
+ $this->assertDocumentExists('Child', $child2->id());
+
+ }
+
}
@@ -81,7 +81,7 @@ public function getValue(){
*/
public function __getRawValue()
{
- if(!is_null($this->Value) && is_null($this->Reference)){
+ if(!is_null($this->Value)) {
if($this->Value->state() != Morph_Enum::STATE_CLEAN){
//save value
Morph_Storage::instance()->save($this->Value);

0 comments on commit f577bfb

Please sign in to comment.