From eab6bb13b9efb3e1c6d725368368de4d74b00946 Mon Sep 17 00:00:00 2001 From: wei <> Date: Mon, 7 May 2007 04:17:37 +0000 Subject: Update Active Record docs. --- .../ActiveRecord/Relations/TActiveRecordBelongsTo.php | 2 +- .../Relations/TActiveRecordHasManyAssociation.php | 18 ++++++++++++------ .../ActiveRecord/Relations/TActiveRecordRelation.php | 4 ---- .../Relations/TActiveRecordRelationContext.php | 13 +++++++++++-- 4 files changed, 24 insertions(+), 13 deletions(-) (limited to 'framework/Data/ActiveRecord/Relations') diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php b/framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php index 9374af64..02d0b0e3 100644 --- a/framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php +++ b/framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php @@ -51,7 +51,7 @@ Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelation'); * } * * The static $RELATIONS property of PlayerRecord defines that the - * property $team belongs to (or is a) TeamRecords. + * property $team belongs to a TeamRecord. * * The team object may be fetched as follows. * diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php b/framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php index e83ca37f..65989639 100644 --- a/framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php +++ b/framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php @@ -158,13 +158,16 @@ class TActiveRecordHasManyAssociation extends TActiveRecordRelation } /** - * @return TDbCommandBuilder + * @return TDataGatewayCommand */ protected function getCommandBuilder() { return $this->getSourceRecord()->getRecordGateway()->getCommand($this->getSourceRecord()); } + /** + * @return TDataGatewayCommand + */ protected function getForeignCommandBuilder() { $obj = $this->getContext()->getForeignRecordFinder(); @@ -314,13 +317,16 @@ class TActiveRecordHasManyAssociation extends TActiveRecordRelation return $success; } + /** + * @return TDbCommandBuilder + */ protected function getAssociationTableCommandBuilder() { $conn = $this->getContext()->getSourceRecord()->getDbConnection(); return $this->getAssociationTable()->createCommandBuilder($conn); } - protected function hasAssociationData($builder,$data) + private function hasAssociationData($builder,$data) { $condition=array(); $table = $this->getAssociationTable(); @@ -331,13 +337,13 @@ class TActiveRecordHasManyAssociation extends TActiveRecordRelation return intval($result) > 0; } - protected function addAssociationData($builder,$data) + private function addAssociationData($builder,$data) { $command = $builder->createInsertCommand($data); return $this->getCommandBuilder()->onExecuteCommand($command, $command->execute()) > 0; } - protected function updateAssociationTable($obj,$fkObjects, $builder) + private function updateAssociationTable($obj,$fkObjects, $builder) { $source = $this->getSourceRecordValues($obj); $foreignKeys = $this->findForeignKeys($this->getAssociationTable(), $fkObjects[0]); @@ -351,7 +357,7 @@ class TActiveRecordHasManyAssociation extends TActiveRecordRelation return $success; } - protected function getSourceRecordValues($obj) + private function getSourceRecordValues($obj) { $sourceKeys = $this->findForeignKeys($this->getAssociationTable(), $obj); $indexValues = $this->getIndexValues(array_values($sourceKeys), $obj); @@ -362,7 +368,7 @@ class TActiveRecordHasManyAssociation extends TActiveRecordRelation return $data; } - protected function getForeignObjectValues($foreignKeys,$fkObject) + private function getForeignObjectValues($foreignKeys,$fkObject) { $data=array(); foreach($foreignKeys as $name=>$fKey) diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php b/framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php index 4dc9743f..60afef89 100644 --- a/framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php +++ b/framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php @@ -191,10 +191,6 @@ abstract class TActiveRecordRelation $prop = $this->getContext()->getProperty(); $source->{$prop} = isset($collections[$hash]) ? $collections[$hash] : array(); } - - public function updateAssociatedRecords() - { - } } ?> \ No newline at end of file diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordRelationContext.php b/framework/Data/ActiveRecord/Relations/TActiveRecordRelationContext.php index 12f2a874..16b29861 100644 --- a/framework/Data/ActiveRecord/Relations/TActiveRecordRelationContext.php +++ b/framework/Data/ActiveRecord/Relations/TActiveRecordRelationContext.php @@ -182,7 +182,6 @@ class TActiveRecordRelationContext */ public function updateAssociatedRecords($updateBelongsTo=false) { - Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelationCommand'); $success=true; foreach($this->getRecordRelationships() as $property=>$relation) { @@ -190,7 +189,7 @@ class TActiveRecordRelationContext if(($updateBelongsTo && $belongsTo) || (!$updateBelongsTo && !$belongsTo)) { $obj = $this->getSourceRecord(); - if(!empty($obj->{$property})) + if(!$this->isEmptyFkObject($obj->{$property})) { $context = new self($this->getSourceRecord(),$property); $success = $context->getRelationHandler()->updateAssociatedRecords() && $success; @@ -199,6 +198,16 @@ class TActiveRecordRelationContext } return $success; } + + protected function isEmptyFkObject($obj) + { + if(is_object($obj)) + return $obj instanceof TList ? $obj->count() === 0 : false; + else if(is_array($obj)) + return count($obj)===0; + else + return empty($obj); + } } ?> \ No newline at end of file -- cgit v1.2.3