/** * 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}"; }
/** * Unlink the field mapping of the referenced record for the old owning record * * @param Record $referencedRecord */ private function unlinkFieldMappingForOldOwningRecord(Record $referencedRecord) { if (!$this->relation->isOneToOne()) { return; } $refId = $referencedRecord->getInternalId(); if (!$this->isReferenced($refId)) { return; } $oldOwningId = $this->getOwning($refId); $repositoryOwningSide = $this->getRefRepository($referencedRecord, $this->relation->getOwningAlias()); if ($repositoryOwningSide->hasByInternalId($oldOwningId)) { $owningField = $this->relation->getOwningField(); $oldOwningRecord = $repositoryOwningSide->getByInternalId($oldOwningId); $oldOwningRecord->set($owningField, null); $this->unsetFieldMapping($oldOwningRecord->getOid()); } }
/** * Sets owning record reference to the referenced record given by it's id * * @param Record $record * @param string $newId */ public function setOwningReferenceByForeignKey(Record $record, $newId) { if (!$newId) { return; } $id = $record->getInternalId(); if ($this->relation->isOneToMany()) { $refRepository = $this->getRefRepository($record, $this->relation->getOwningAlias()); $newRefRecord = $refRepository->getByInternalId($newId); if ($newRefRecord) { $relatedCollection = $this->getRelatedCollection($newRefRecord->getOid()); // TODO exception, or if not set create one?? if ($relatedCollection) { $relatedCollection->add($record); } } } $this->assignReference($newId, $id); }