fix relation population

This commit is contained in:
Dennis Eichhorn 2020-03-31 18:23:46 +02:00
parent 3997d9563e
commit 9e96b89aa0
2 changed files with 6 additions and 10 deletions

View File

@ -636,6 +636,7 @@ class DataMapperAbstract implements DataMapperInterface
}
self::createRelationTable($member, \is_array($id2) ? $id2 : [$id2], $id1);
self::removeInitialized(static::class, $id1);
return true;
}
@ -2439,10 +2440,7 @@ class DataMapperAbstract implements DataMapperInterface
self::addInitialized(static::class, $value, $obj[$value]);
$obj[$value] = self::populateAbstract($row, $obj[$value], $depth);
foreach (static::$hasMany as $many) {
self::fillRelations($obj[$value], $relations, $depth - 1);
}
self::fillRelations($obj[$value], $relations, $depth - 1);
}
}
@ -2510,10 +2508,7 @@ class DataMapperAbstract implements DataMapperInterface
$obj[$value] = self::populateAbstractArray($row, [], $depth);
self::addInitializedArray(static::class, $value, $obj[$value]);
foreach (static::$hasMany as $many) {
self::fillRelationsArray(${$obj}[$value], $relations, $depth - 1);
}
self::fillRelationsArray($obj[$value], $relations, $depth - 1);
}
self::clear();
@ -2766,14 +2761,14 @@ class DataMapperAbstract implements DataMapperInterface
return;
}
$key = $obj[$mapper::$columns[$mapper::$primaryField]['internal']];
$key = $obj[static::$columns[static::$primaryField]['internal']];
if (empty($key)) {
return;
}
/* loading relations from relations table and populating them and then adding them to the object */
self::populateManyToManyArray(self::getHasManyRaw($key, $mapper, $relations), $obj[$key], $depth);
self::populateManyToManyArray(self::getHasManyRaw($key, $relations), $obj, $depth);
}
/**

View File

@ -283,6 +283,7 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_direct')->execute();
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_rel')->execute();
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_rel_relations')->execute();
BaseModelMapper::clearCache();
}
/**