Inheritance: extends Storm\Drivers\Base\Relational\RelationalTableTrait
Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 3
0
 /**
  * @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;
     }
 }
Ejemplo n.º 4
0
 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);
             }
         });
     }
 }
Ejemplo n.º 5
0
 public function DropForeignKey(IConnection $Connection, QueryBuilder $QueryBuilder, Table $Table, Traits\ForeignKey $Trait)
 {
     QueryBuilderExtensions::AppendAlterTable($QueryBuilder, $Table);
     $QueryBuilder->AppendIdentifier('DROP FOREIGN KEY #', [$Trait->GetName()]);
 }