Open bbrody opened 4 years ago
Yeah, I don't think that will work out of the box. It's possibly a bug.
Hi! Any updates on this issue?
You can fix this by editing the eagerLoadOnCollection method in vendor/vlucas/spot2/lib/Relation/HasManyThrough.php and changing this: foreach ($collectionRelations as $relatedEntity) { $relatedEntityPk = $relatedEntity->$relationRelatedForeignKey;
if ($relatedEntityPk == $throughForeignKey) {
$entityRelations[$throughLocalKey][] = $relatedEntity;
}
}
to this:
foreach ($collectionRelations as $idx=>$relatedEntity) { $relatedEntityPk = $relatedEntity->$relationRelatedForeignKey;
if ($relatedEntityPk == $throughForeignKey) {
$entityRelations[$throughLocalKey][$idx] = $relatedEntity;
}
} if(is_array($entityRelations[$throughLocalKey])) { ksort($entityRelations[$throughLocalKey]); }
I have
ProjectEntity
with such relation in it'users' => $mapper->hasManyThrough($entity, 'Api\V2\Entities\UserEntity', 'Api\V2\Entities\UserProjectEntity', 'user_id', 'project_id')->active()->order(['displayname' => 'ASC'])
->order()
does not affect on the result, its sorted by id ofUserProjectEntity
(it has simple structureid - user_id -project_id
)