summaryrefslogtreecommitdiff
path: root/framework/Data/ActiveRecord/Relations
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Data/ActiveRecord/Relations')
-rw-r--r--framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php20
-rw-r--r--framework/Data/ActiveRecord/Relations/TActiveRecordHasMany.php12
-rw-r--r--framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php10
-rw-r--r--framework/Data/ActiveRecord/Relations/TActiveRecordHasOne.php17
-rw-r--r--framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php2
-rw-r--r--framework/Data/ActiveRecord/Relations/TActiveRecordRelationContext.php3
6 files changed, 23 insertions, 41 deletions
diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php b/framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php
index c030f2d2..565070c1 100644
--- a/framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php
+++ b/framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php
@@ -123,20 +123,16 @@ class TActiveRecordBelongsTo extends TActiveRecordRelation
{
$obj = $this->getContext()->getSourceRecord();
$fkObject = $obj->getColumnValue($this->getContext()->getProperty());
- $registry = $fkObject->getRecordManager()->getObjectStateRegistry();
- if($registry->shouldPersistObject($fkObject))
+ if($fkObject!==null)
{
- if($fkObject!==null)
- {
- $fkObject->save();
- $source = $this->getSourceRecord();
- $fkeys = $this->findForeignKeys($source, $fkObject);
- foreach($fkeys as $srcKey => $fKey)
- $source->setColumnValue($srcKey, $fkObject->getColumnValue($fKey));
- return true;
- }
+ $fkObject->save();
+ $source = $this->getSourceRecord();
+ $fkeys = $this->findForeignKeys($source, $fkObject);
+ foreach($fkeys as $srcKey => $fKey)
+ $source->setColumnValue($srcKey, $fkObject->getColumnValue($fKey));
+ return true;
}
- return true;
+ return false;
}
}
diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordHasMany.php b/framework/Data/ActiveRecord/Relations/TActiveRecordHasMany.php
index f7426862..382d9789 100644
--- a/framework/Data/ActiveRecord/Relations/TActiveRecordHasMany.php
+++ b/framework/Data/ActiveRecord/Relations/TActiveRecordHasMany.php
@@ -88,7 +88,7 @@ class TActiveRecordHasMany extends TActiveRecordRelation
/**
* @return array foreign key field names as key and object properties as value.
* @since 3.1.2
- */
+ */
public function getRelationForeignKeys()
{
$fkObject = $this->getContext()->getForeignRecordFinder();
@@ -107,16 +107,12 @@ class TActiveRecordHasMany extends TActiveRecordRelation
if(($total = count($fkObjects))> 0)
{
$source = $this->getSourceRecord();
- $registry = $source->getRecordManager()->getObjectStateRegistry();
$fkeys = $this->findForeignKeys($fkObjects[0], $source);
for($i=0;$i<$total;$i++)
{
- if($registry->shouldPersistObject($fkObjects[$i]))
- {
- foreach($fkeys as $fKey => $srcKey)
- $fkObjects[$i]->setColumnValue($fKey, $source->getColumnValue($srcKey));
- $success = $fkObjects[$i]->save() && $success;
- }
+ foreach($fkeys as $fKey => $srcKey)
+ $fkObjects[$i]->setColumnValue($fKey, $source->getColumnValue($srcKey));
+ $success = $fkObjects[$i]->save() && $success;
}
}
return $success;
diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php b/framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php
index 564d3d22..bcda962c 100644
--- a/framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php
+++ b/framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php
@@ -189,7 +189,6 @@ class TActiveRecordHasManyAssociation extends TActiveRecordRelation
{
$criteria = $this->getCriteria();
$finder = $this->getContext()->getForeignRecordFinder();
- $registry = $finder->getRecordManager()->getObjectStateRegistry();
$type = get_class($finder);
$command = $this->createCommand($criteria, $foreignKeys,$indexValues,$sourceKeys);
$srcProps = array_keys($sourceKeys);
@@ -201,7 +200,6 @@ class TActiveRecordHasManyAssociation extends TActiveRecordRelation
unset($row[$column]);
$obj = $this->createFkObject($type,$row,$foreignKeys);
$collections[$hash][] = $obj;
- $registry->registerClean($obj);
}
$this->setResultCollection($results, $collections, array_values($sourceKeys));
}
@@ -214,7 +212,7 @@ class TActiveRecordHasManyAssociation extends TActiveRecordRelation
*/
protected function createFkObject($type,$row,$foreignKeys)
{
- $obj = new $type($row);
+ $obj = TActiveRecord::createRecordInstance($type, $row, TActiveRecord::STATE_LOADED);
if(count($this->_association_columns) > 0)
{
$i=0;
@@ -309,13 +307,9 @@ class TActiveRecordHasManyAssociation extends TActiveRecordRelation
if(($total = count($fkObjects))> 0)
{
$source = $this->getSourceRecord();
- $registry = $source->getRecordManager()->getObjectStateRegistry();
$builder = $this->getAssociationTableCommandBuilder();
for($i=0;$i<$total;$i++)
- {
- if($registry->shouldPersistObject($fkObjects[$i]))
- $success = $fkObjects[$i]->save() && $success;
- }
+ $success = $fkObjects[$i]->save() && $success;
return $this->updateAssociationTable($obj, $fkObjects, $builder) && $success;
}
return $success;
diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordHasOne.php b/framework/Data/ActiveRecord/Relations/TActiveRecordHasOne.php
index e5a36659..49119965 100644
--- a/framework/Data/ActiveRecord/Relations/TActiveRecordHasOne.php
+++ b/framework/Data/ActiveRecord/Relations/TActiveRecordHasOne.php
@@ -100,7 +100,7 @@ class TActiveRecordHasOne extends TActiveRecordRelation
$fkObjects = $this->findForeignObjects($fields,$indexValues);
$this->populateResult($results,$properties,$fkObjects,$fields);
}
-
+
/**
* @return array foreign key field names as key and object properties as value.
* @since 3.1.2
@@ -135,16 +135,11 @@ class TActiveRecordHasOne extends TActiveRecordRelation
public function updateAssociatedRecords()
{
$fkObject = $this->getContext()->getPropertyValue();
- $registry = $fkObject->getRecordManager()->getObjectStateRegistry();
- if($registry->shouldPersistObject($fkObject))
- {
- $source = $this->getSourceRecord();
- $fkeys = $this->findForeignKeys($fkObject, $source);
- foreach($fkeys as $fKey => $srcKey)
- $fkObject->setColumnValue($fKey, $source->getColumnValue($srcKey));
- return $fkObject->save();
- }
- return true;
+ $source = $this->getSourceRecord();
+ $fkeys = $this->findForeignKeys($fkObject, $source);
+ foreach($fkeys as $fKey => $srcKey)
+ $fkObject->setColumnValue($fKey, $source->getColumnValue($srcKey));
+ return $fkObject->save();
}
}
diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php b/framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php
index 5bde4898..63e182ca 100644
--- a/framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php
+++ b/framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php
@@ -162,7 +162,7 @@ abstract class TActiveRecordRelation
$ids=array();
foreach($properties as $property)
$ids[] = is_object($obj) ? $obj->getColumnValue($property) : $obj[$property];
- return sprintf('%x',crc32(serialize($ids)));
+ return serialize($ids);
}
/**
diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordRelationContext.php b/framework/Data/ActiveRecord/Relations/TActiveRecordRelationContext.php
index 8bc4362f..d6f86a9a 100644
--- a/framework/Data/ActiveRecord/Relations/TActiveRecordRelationContext.php
+++ b/framework/Data/ActiveRecord/Relations/TActiveRecordRelationContext.php
@@ -182,8 +182,9 @@ class TActiveRecordRelationContext
public function updateAssociatedRecords($updateBelongsTo=false)
{
$success=true;
- foreach($this->_record->getRelations() as $property=>$relation)
+ foreach($this->_record->getRelations() as $data)
{
+ list($property, $relation) = $data;
$belongsTo = $relation[0]==TActiveRecord::BELONGS_TO;
if(($updateBelongsTo && $belongsTo) || (!$updateBelongsTo && !$belongsTo))
{