/**
  * Returns the description of the failure
  *
  * The beginning of failure messages is "Failed asserting that" in most
  * cases. This method should return the second part of that sentence.
  *
  * @param  Relation $relation Evaluated value or object.
  * @return string
  */
 protected function failureDescription($relation)
 {
     $owningAlias = $relation->getOwningAlias();
     $owningTable = $relation->getOwningTable();
     $referencedAlias = $relation->getReferencedAlias();
     $referencedTable = $relation->getReferencedTable();
     return $this->toString() . "{$owningTable}->{$referencedAlias}: {$referencedTable} | {$referencedTable}->{$owningAlias}: {$owningTable}";
 }
예제 #2
0
 /**
  * @param string $newIdentifier
  * @param string $oldIdentifier
  * @param Record $owningRecord
  */
 public function updateOwningIdentifier($newIdentifier, $oldIdentifier, Record $owningRecord)
 {
     $relationName = $this->relation->getReferencedAlias();
     if (!$this->relation->hasReferenceLoadedFor($owningRecord, $relationName)) {
         return;
     }
     $referencedRecord = $this->relation->getReferenceFor($owningRecord, $relationName);
     if ($referencedRecord) {
         $refId = $referencedRecord->getInternalId();
         $this->updateReferenceInMap($refId, $newIdentifier, $oldIdentifier);
     }
 }
예제 #3
0
 /**
  * Removes owning record from record collection belonging to the referenced record given by it's id
  *
  * @param Record $record
  * @param string $referencedId
  */
 public function removeOwningReferenceForeignKey(Record $record, $referencedId)
 {
     if (!$referencedId || !$this->isReferenced($referencedId)) {
         return;
     }
     if ($this->relation->isOneToMany()) {
         $owningId = $record->getInternalId();
         $this->removeOwningReference($referencedId, $owningId);
         $refRepository = $this->getRefRepository($record, $this->relation->getReferencedAlias());
         $oldRefRecord = $refRepository->getByInternalId($referencedId);
         if ($oldRefRecord) {
             $relatedCollection = $this->getRelatedCollection($oldRefRecord->getOid());
             // TODO exception, or if not set create one??
             if ($relatedCollection) {
                 $relatedCollection->unlinkRecord($record);
             }
         }
     } else {
         $this->setReference($referencedId, null);
     }
 }