summaryrefslogtreecommitdiff
path: root/framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php
diff options
context:
space:
mode:
authorwei <>2007-05-04 08:37:12 +0000
committerwei <>2007-05-04 08:37:12 +0000
commit8708f7e88e423b44ea4b3b8fff14f055d2b5c4ac (patch)
treef468f8990c7675089f804914453ba994d0c1be30 /framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php
parentc1bddf3826ec570ea4c58d7a56c410ae54d26508 (diff)
Add saving/updating ActiveRecord relationships.
Diffstat (limited to 'framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php')
-rw-r--r--framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php24
1 files changed, 24 insertions, 0 deletions
diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php b/framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php
index 1168bf55..9374af64 100644
--- a/framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php
+++ b/framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php
@@ -104,6 +104,30 @@ class TActiveRecordBelongsTo extends TActiveRecordRelation
$source->{$prop} = $collections[$hash][0];
}
}
+
+ /**
+ * Updates the source object first.
+ * @return boolean true if all update are success (including if no update was required), false otherwise .
+ */
+ public function updateAssociatedRecords()
+ {
+ $obj = $this->getContext()->getSourceRecord();
+ $fkObject = $obj->{$this->getContext()->getProperty()};
+ $registry = $fkObject->getRecordManager()->getObjectStateRegistry();
+ if($registry->shouldPersistObject($fkObject))
+ {
+ if($fkObject!==null)
+ {
+ $fkObject->save();
+ $source = $this->getSourceRecord();
+ $fkeys = $this->findForeignKeys($source, $fkObject);
+ foreach($fkeys as $srcKey => $fKey)
+ $source->{$srcKey} = $fkObject->{$fKey};
+ return true;
+ }
+ }
+ return true;
+ }
}
?> \ No newline at end of file