protected function GroupRelatedRowsByParentKeys(array &$MappedRelatedRows, ForeignKey $ForeignKey, array $ParentRows, array $RelatedRows) { $ReferencedColumns = $ForeignKey->GetReferencedColumns(); $ParentColumns = $ForeignKey->GetParentColumns(); $GroupedRelatedRows = $this->GroupRowsByColumnValues($RelatedRows, $ParentColumns); $this->MapParentRowKeysToGroupedRelatedRows($MappedRelatedRows, $ParentRows, $ReferencedColumns, $GroupedRelatedRows); }
public function __construct(ForeignKey $ForeignKey) { $ReferencedColumnMap = $ForeignKey->GetReferencedColumnMap(); $ConstraintExpressions = []; foreach ($ReferencedColumnMap as $PrimaryColumn) { $ForeignColumn = $ReferencedColumnMap[$PrimaryColumn]; $ConstraintExpressions[] = Expression::BinaryOperation(Expression::Column($PrimaryColumn), Binary::Equality, Expression::Column($ForeignColumn)); } parent::__construct($ConstraintExpressions, Binary::LogicalAnd); }
/** * @return Relational\ResultRow */ protected function MapParentRowToRelatedKey(ForeignKey $ForeignKey, Relational\ResultRow $ParentRow) { if ($this->IsInversed) { $ParentKey = $ForeignKey->ParentKey(); $ForeignKey->MapReferencedToParentKey($ParentRow, $ParentKey); return $ParentKey; } else { $ReferencedKey = $ForeignKey->ReferencedKey(); $ForeignKey->MapParentToReferencedKey($ParentRow, $ReferencedKey); return $ReferencedKey; } }
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 DropForeignKey(IConnection $Connection, QueryBuilder $QueryBuilder, Table $Table, Traits\ForeignKey $Trait) { QueryBuilderExtensions::AppendAlterTable($QueryBuilder, $Table); $QueryBuilder->AppendIdentifier('DROP FOREIGN KEY #', [$Trait->GetName()]); }