SubscribeToPrePersistEvent() public method

Subscribe a callback to when the supplied row will be persisted.
public SubscribeToPrePersistEvent ( Storm\Core\Relational\ITable $Table, callable $Event )
$Table Storm\Core\Relational\ITable
$Event callable
Ejemplo n.º 1
0
 protected function PersistIdentifyingRelationship(Relational\Transaction $Transaction, Relational\ResultRow $ParentData, array $ChildRows)
 {
     if ($this->GetForeignKey()->HasReferencedKey($ParentData)) {
         foreach ($ChildRows as $ChildRow) {
             $this->MapRelationalParentDataToRelatedData($ParentData, $ChildRow);
         }
     } else {
         $Transaction->SubscribeToPrePersistEvent($this->GetTable(), function () use(&$ParentData, &$ChildRows) {
             foreach ($ChildRows as $ChildRow) {
                 $this->MapRelationalParentDataToRelatedData($ParentData, $ChildRow);
             }
         });
     }
 }
Ejemplo n.º 2
0
 protected final function PersistIdentifyingRelationship(Relational\Transaction $Transaction, Relational\ResultRow $ParentData, Relational\ResultRow $ChildData)
 {
     $ForeignKey = $this->GetForeignKey();
     /**
      * In case the foreign key is part of the primary key and the row has
      * not been persisted yet.
      */
     $HasForeignKey = $this->IsInversed() ? $ForeignKey->HasReferencedKey($ParentData) : $ForeignKey->HasParentKey($ParentData);
     if ($HasForeignKey) {
         $this->MapRelationalParentDataToRelatedData($ParentData, $ChildData);
     } else {
         $Transaction->SubscribeToPrePersistEvent($ChildData, function () use(&$ParentData, &$ChildData) {
             $this->MapRelationalParentDataToRelatedData($ParentRow, $ChildRow);
         });
     }
 }
Ejemplo n.º 3
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);
             }
         });
     }
 }