-
Notifications
You must be signed in to change notification settings - Fork 21
Updating properties in 'remote' DomainObject is broken #79
Conversation
@@ -179,6 +181,19 @@ public function testArrayAccess() | |||
$this->assertEquals("Joe", $llama['name']); | |||
} | |||
|
|||
public function testReadingRemoteProperty() | |||
{ | |||
$hero = (new Hero(array('alias' => 'Mr. Incredible')))->save(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this syntax will fail in PHP 5.3.
Pheasant doesn't maintain any internal identity maps. A call to a relationship will always return a brand new object. The new |
Is this something we would like to solve? Otherwise I'd say this is something that needs a place in the documentation. |
Yup, I think this needs to be very clearly documented. Alternately, it's possible we could accomplish this behavior with a per-relationship cache. |
A cache might be a good thing, as we don't cache relationships before sending them to our templates. This currently results in a lot of unnecessary trips to the database:
|
I believe that the |
I'd like to reopen this, as it seems like the intended behavior in this issue is actually happening. We have two domain objects Suppose # In CreditProduct afterSave, we save the credit to bust caches, etc
# function afterSave(){
# $this->credit->save();
# }
# In a controller:
$credit = Credit::find(1);
$credit->reason = "Hello";
$credit_product = CreditProduct::create(array(
'credit_id' => $credit->id,
'product_id' => 2,
));
# "Hello" has been saved to the db as the credit reason,
# even though the afterSave function in CreditProduct should get a new instance. |
I guess the testcase is clear :-).