diff options
Diffstat (limited to 'framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php')
-rw-r--r-- | framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php | 24 |
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 |