You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.
Problem
I have one problem with eager loading to be exact with ordering in with() method. I use cache that generates key from SQL query.
I noticed that I have same cache value store multiple times under different key. After some testing I found a problem what with() method does not reorder foreign keys prior database query call.
Example: I have few models: town and street and they are connected via relationship. If on a first page I would call: street::with('town')->paginate(10) the SQL query for with() would look like: select * from `towns` where `towns`.`id` in ('1, '2', '3') but on a second page it looks like: select * from `towns` where `towns`.`id` in ('2, '1', '3') and here is the problem that it returns same SQL result but from to different yet same queries.
Laravel Version: 5.4
PHP Version: 7.0.14
Database Driver & Version: MySQL 5.5.53
Problem
I have one problem with eager loading to be exact with ordering in with() method. I use cache that generates key from SQL query.
I noticed that I have same cache value store multiple times under different key. After some testing I found a problem what with() method does not reorder foreign keys prior database query call.
Example: I have few models: town and street and they are connected via relationship. If on a first page I would call: street::with('town')->paginate(10) the SQL query for with() would look like:
select * from `towns` where `towns`.`id` in ('1, '2', '3')
but on a second page it looks like:select * from `towns` where `towns`.`id` in ('2, '1', '3')
and here is the problem that it returns same SQL result but from to different yet same queries.Solution
To add sort() or just helper function array_sort_recursive() at functions that returns keys. Same would be for 5.3 version with minor changes at https://github.com/laravel/framework/blob/5.3/src/Illuminate/Database/Eloquent/Relations/Relation.php#L201.
Change:
https://github.com/laravel/framework/blob/5.4/src/Illuminate/Database/Eloquent/Relations/Relation.php#L201
To:
and Change:
https://github.com/laravel/framework/blob/5.4/src/Illuminate/Database/Eloquent/Relations/BelongsTo.php#L133
To:
The text was updated successfully, but these errors were encountered: