Karaka-Management / phpOMS

PHP Framework
Other
2 stars 0 forks source link

Optimize special hasMany case where only one has many case will be selected. #363

Open spl1nes opened 7 months ago

spl1nes commented 7 months ago

If only one has many case is selected it shouldn't perform a child request but rather perform a join.

$tasks = TaskMapper::getAll()
            ->with('tags')
            ->with('tags/title')
            ->with('taskElements')
            ->where('title', '%' . ($request->getDataString('search') ?? '') . '%', 'LIKE')
            ->where('tags/title/language', $response->header->l11n->language)
            ->sort('createdAt', OrderType::DESC)
            ->sort('taskElements/createdAt', OrderType::ASC)
            ->limit(25)
            ->limit(1, 'taskElements')
            ->execute();

Careful, there is another bug relating limit on has many members.

There is also a variation of this discussed in the ReadMapper with localizations as example.