summaryrefslogtreecommitdiff
path: root/framework/Data/ActiveRecord/Relations
diff options
context:
space:
mode:
authorwei <>2007-05-07 04:17:37 +0000
committerwei <>2007-05-07 04:17:37 +0000
commiteab6bb13b9efb3e1c6d725368368de4d74b00946 (patch)
tree57aa3462b6f18ad190527483e753dc148971bc63 /framework/Data/ActiveRecord/Relations
parente91ac8550a4e6dfa255874860f108935841c16f6 (diff)
Update Active Record docs.
Diffstat (limited to 'framework/Data/ActiveRecord/Relations')
-rw-r--r--framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php2
-rw-r--r--framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php18
-rw-r--r--framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php4
-rw-r--r--framework/Data/ActiveRecord/Relations/TActiveRecordRelationContext.php13
4 files changed, 24 insertions, 13 deletions
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');
* }
* </code>
* The static <tt>$RELATIONS</tt> property of PlayerRecord defines that the
- * property <tt>$team</tt> belongs to (or is a) <tt>TeamRecord</tt>s.
+ * property <tt>$team</tt> belongs to a <tt>TeamRecord</tt>.
*
* The team object may be fetched as follows.
* <code>
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