Hi,
I am fetching Users data from users Table with Relations using this query function
queryBuilder.setRelated( [ “auctions”, “user_children” ] )
suppose user have more than 10 auctions then in which Order 10 object of auction’s of users will come ??
Hello @Ayaz_Khan
There is no sorting when related objects are returned. They will return in the order that the Database returns them.
Regards,
Inna
Is there any way to get related objects in a specific Order Like I want to get the latest 10 related records of every user?
Hi.
I can advise two approaches. What will better depends on your type of work (desired read-write ratio).
Prerequisite:
- two tables - A and B;
- relation A ← B (so, several records from B refers to one record in A);
- we need for specific set of records from A take n sorted records from B;
(1)
In one transaction you can make:
- request the IDs of all interesting objects from A;
- and add for each objectId from A separate request to table B;
(2)
You can create specific “Result” table which will contain prepared data and create EventHandler which responsibility will be to keep that Result table in actual state. Thus for each insert/update in tables A or B the handler should make changes in the Result table.
(3)
The same as in (2) but without handlers. Instead you can use Timers to process data in tables A/B at regular intervals.