Skip to content

Commit

Permalink
[hotfix] Use column name provided by FK instead of defaulting to first (
Browse files Browse the repository at this point in the history
#254)

Signed-off-by: Dorian Savina <[email protected]>
  • Loading branch information
dsavina authored and homersimpsons committed Apr 20, 2021
1 parent 3465791 commit ed04e36
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/DbRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,15 +395,16 @@ private function buildDbRow(array $dbRow, array $references): array

if ($reference !== null) {
$refDbRows = $reference->_getDbRows();
$firstRefDbRow = reset($refDbRows);
if ($firstRefDbRow === false) {
$refDbRow = $refDbRows[$fk->getForeignTableName()] ?? false;

if ($refDbRow === false) {
throw new \RuntimeException('Unexpected error: empty refDbRows'); // @codeCoverageIgnore
}
if ($firstRefDbRow->_getStatus() === TDBMObjectStateEnum::STATE_DELETED) {
if ($refDbRow->_getStatus() === TDBMObjectStateEnum::STATE_DELETED) {
throw TDBMMissingReferenceException::referenceDeleted($this->dbTableName, $reference);
}
$foreignColumns = $fk->getUnquotedForeignColumns();
$refBeanValues = $firstRefDbRow->dbRow;
$refBeanValues = $refDbRow->dbRow;
for ($i = 0, $count = \count($localColumns); $i < $count; ++$i) {
$dbRow[$localColumns[$i]] = $refBeanValues[$foreignColumns[$i]];
}
Expand Down

0 comments on commit ed04e36

Please sign in to comment.