From 8708f7e88e423b44ea4b3b8fff14f055d2b5c4ac Mon Sep 17 00:00:00 2001 From: wei <> Date: Fri, 4 May 2007 08:37:12 +0000 Subject: Add saving/updating ActiveRecord relationships. --- .../ActiveRecord/TActiveRecordStateRegistry.php | 27 ++++++++++++++-------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'framework/Data/ActiveRecord/TActiveRecordStateRegistry.php') diff --git a/framework/Data/ActiveRecord/TActiveRecordStateRegistry.php b/framework/Data/ActiveRecord/TActiveRecordStateRegistry.php index d6f24961..7a285274 100644 --- a/framework/Data/ActiveRecord/TActiveRecordStateRegistry.php +++ b/framework/Data/ActiveRecord/TActiveRecordStateRegistry.php @@ -97,7 +97,7 @@ class TActiveRecordStateRegistry public function registerClean($obj) { $this->removeCleanOrDirty($obj); - if($this->getIsRemovedObject($obj)) + if($this->isRemovedObject($obj)) throw new TActiveRecordException('ar_object_marked_for_removal'); $this->_cleanObjects[] = array($obj, clone($obj)); } @@ -152,7 +152,7 @@ class TActiveRecordStateRegistry * @param TActiveRecord object to test. * @return boolean true if the object is dirty, false otherwise. */ - public function getIsDirtyObject($obj) + public function isDirtyObject($obj) { foreach($this->_cleanObjects as $cache) if($cache[0] === $obj) @@ -165,7 +165,7 @@ class TActiveRecordStateRegistry * @param TActiveRecord object to test. * @return boolean true if object is clean, false otherwise. */ - public function getIsCleanObject($obj) + public function isCleanObject($obj) { foreach($this->_cleanObjects as $cache) if($cache[0] === $obj) @@ -178,21 +178,30 @@ class TActiveRecordStateRegistry * @param TActiveRecord object to test. * @return boolean true if object is newly created, false otherwise. */ - public function getIsNewObject($obj) + public function isNewObject($obj) { - if($this->getIsRemovedObject($obj)) return false; + if($this->isRemovedObject($obj)) return false; foreach($this->_cleanObjects as $cache) if($cache[0] === $obj) return false; return true; } + /** + * @param TActiveRecord object to test. + * @return boolean true if object is dirty or is new. + */ + public function shouldPersistObject($obj) + { + return $this->isDirtyObject($obj) || $this->isNewObject($obj); + } + /** * Test whether an object is marked for deletion. * @param TActiveRecord object to test. * @return boolean true if object is marked for deletion, false otherwise. */ - public function getIsRemovedObject($obj) + public function isRemovedObject($obj) { return $this->_removedObjects->contains($obj); } @@ -211,7 +220,7 @@ class TActiveRecordStateRegistry { $rowsAffected=false; - if($this->getIsRemovedObject($record)) + if($this->isRemovedObject($record)) { $rowsAffected = $gateway->delete($record); if($rowsAffected) @@ -219,9 +228,9 @@ class TActiveRecordStateRegistry } else { - if($this->getIsDirtyObject($record)) + if($this->isDirtyObject($record)) $rowsAffected = $gateway->update($record); - else if($this->getIsNewObject($record)) + else if($this->isNewObject($record)) $rowsAffected = $gateway->insert($record); if($rowsAffected) -- cgit v1.2.3