public function Persist(Relational\Transaction $Transaction, Relational\ResultRow $ParentData, array $RelationshipChanges) { /* @var $RelationshipChanges Relational\RelationshipChange[] */ $JoinRowsWithoutPrimaryKeys = []; foreach ($RelationshipChanges as $RelationshipChange) { if ($RelationshipChange->HasPersistedRelationship()) { $JoinRow = $this->MapPersistedRelationshipToJoinRow($RelationshipChange->GetPersistedRelationship()); $Transaction->Persist($JoinRow); if (!$JoinRow->HasPrimaryKey()) { $JoinRowsWithoutPrimaryKeys[] = $JoinRow; } } if ($RelationshipChange->HasDiscardedRelationship()) { $JoinRow = $this->MapDiscardedRelationshipToJoinRow($RelationshipChange->GetDiscardedRelationship()); $Transaction->Discard($JoinRow->GetPrimaryKey()); } } if (count($JoinRowsWithoutPrimaryKeys) > 0) { $ParentRow = $ParentData->GetRow($this->ParentForeignKey->GetReferencedTable()); $Transaction->SubscribeToPrePersistEvent($this->JoinTable, function () use(&$ParentRow, &$JoinRowsWithoutPrimaryKeys) { foreach ($JoinRowsWithoutPrimaryKeys as $JoinRowWithoutPrimaryKey) { $this->ParentForeignKey->MapReferencedToParentKey($ParentRow, $JoinRowWithoutPrimaryKey); } }); } }
public function Persist(Relational\Transaction $Transaction, Relational\ResultRow $ParentData, Relational\RelationshipChange $RelationshipChange) { if ($RelationshipChange->HasPersistedRelationship()) { $PersistedRelationship = $RelationshipChange->GetPersistedRelationship(); if ($PersistedRelationship->IsIdentifying()) { $ParentRow = $ParentData->GetRow($this->GetParentTable()); $ChildRow = $PersistedRelationship->GetChildResultRow()->GetRow($this->GetTable()); $this->PersistIdentifyingRelationship($Transaction, $ParentRow, $ChildRow); } else { $RelatedPrimaryKey = $PersistedRelationship->GetRelatedPrimaryKey(); if ($this->IsInversed()) { $this->GetForeignKey()->MapParentToReferencedKey($RelatedPrimaryKey, $ParentData); } else { $this->GetForeignKey()->MapReferencedToParentKey($RelatedPrimaryKey, $ParentData); } } } }
protected final function GroupRowsByColumnValues(array $ResultRows, array $Columns) { $GroupedRelatedRows = []; $GroupByKeys = Relational\ResultRow::GetAllDataFromColumns($ResultRows, $Columns); foreach ($ResultRows as $Key => $ResultRow) { $Hash = $GroupByKeys[$Key]->HashData(); if (!isset($GroupedRelatedRows[$Hash])) { $GroupedRelatedRows[$Hash] = []; } $GroupedRelatedRows[$Hash][] = $ResultRow; } return $GroupedRelatedRows; }
protected final function IndexRowsByHashedColumnValues(array $ResultRows, array $Columns) { $KeyedRows = []; $ColumnDataArray = Relational\ResultRow::GetAllDataFromColumns($ResultRows, $Columns); foreach ($ResultRows as $Key => $Row) { $Hash = $ColumnDataArray[$Key]->HashData(); $KeyedRows[$Hash] = $Row; } return $KeyedRows; }