lox / pheasant

A lightweight data mapper designed to take advantage of PHP 5.3+
http://getpheasant.com
MIT License
101 stars 21 forks source link

In-Memory cache updating remote objects? #110

Open Jud opened 10 years ago

Jud commented 10 years ago

I posted this on #79 but I think it deserves it's own issue now that #98 has been merged. It appears that the in-memory object cache isn't following the principle of least surprise by allowing callbacks in DomainObjects save instances that were found in controllers.

e.g. We ran into this the other day:

Suppose CreditProduct #1 belongsTo Credit #1.

# 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.