fix broken getForArray implementation

This commit is contained in:
Dennis Eichhorn 2020-06-11 23:39:19 +02:00
parent b7cb3c6a7c
commit 0cee08b087
2 changed files with 12 additions and 8 deletions

View File

@ -2561,15 +2561,16 @@ class DataMapperAbstract implements DataMapperInterface
/**
* Get object.
*
* @param mixed $primaryKey Key
* @param int $relations Load relations
* @param int $depth Relation depth
* @param mixed $primaryKey Key
* @param int $relations Load relations
* @param int $depth Relation depth
* @param string $ref Ref (for getBy and getFor)
*
* @return array
*
* @since 1.0.0
*/
public static function getArray($primaryKey, int $relations = RelationType::ALL, int $depth = 3) : array
public static function getArray($primaryKey, int $relations = RelationType::ALL, int $depth = 3, string $ref = null) : array
{
if ($depth < 1) {
return $primaryKey;
@ -2582,8 +2583,10 @@ class DataMapperAbstract implements DataMapperInterface
$primaryKey = (array) $primaryKey;
$obj = [];
self::$relations = $relations;
foreach ($primaryKey as $key => $value) {
if (!self::isInitializedArray(static::class, $value, $depth)) {
if (!self::isInitializedArray(static::class, $value, $depth) || $ref !== null) {
continue;
}
@ -2591,7 +2594,7 @@ class DataMapperAbstract implements DataMapperInterface
unset($primaryKey[$key]);
}
$dbData = self::getRaw($primaryKey, $relations, $depth);
$dbData = self::getRaw($primaryKey, $relations, $depth, $ref);
if (empty($dbData)) {
$countResulsts = \count($obj);
@ -2682,7 +2685,7 @@ class DataMapperAbstract implements DataMapperInterface
*/
public static function getByArray($byKey, string $by, int $relations = RelationType::ALL, int $depth = 3)
{
return self::get($byKey, $relations, $depth, $by);
return self::getArray($byKey, $relations, $depth, $by);
}
/**

View File

@ -413,12 +413,13 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase
*/
public function testDelete() : void
{
/*
$id = BaseModelMapper::create($this->model);
BaseModelMapper::delete($this->model);
$modelR = BaseModelMapper::get($id);
self::assertInstanceOf('phpOMS\tests\DataStorage\Database\TestModel\NullBaseModel', $modelR);
*/
/**
* @todo Orange-Management/phpOMS#225
* Test the deletion of a model with relations (deleting relations).