On Thu, Jul 29, 2021 at 6:11 AM Michal Macejko <[email protected]>
wrote:
> Hi all,
>
> here's a problem of mine. Member has many MemberIntegration,
> MemberIntegration has many MemberIntegrationField
>
> I need to load paginated members and order id by a
> MemberIntegrationField#value.
>
> In the database I have 100 members.
>
> ActiveRecord:
>
> ```
> Member.includes(member_integrations: [:member_integration_fields]).order('
> member_integration_fields.id').to_a.count
> ```
>
> uses `LEFT OUTER JOIN` and it returns 100 members.
>
> Important thing to know is when I run the plain SQL in the pgAdmin, it
> returns `6XX` members, depends on the associations. It gives me an idea
> that ActiveRecord somehow deletes those duplicates. Not sure how yet.
>
> What would be the sequel alternative for that?
>
> I've tried `eager` but that does not allow me order by child attribute, as
> children associations will be loaded in another query.
>
> I've tried `eager_graph` but I ends up with `6XX` members.
>
> Any idea how to deal with such a query? Thank you
>
It's hard to provide a definitive answer here, since you didn't provide a
self contained example. When you were using eager_graph, did you call #all
on the dataset, or #to_a as in the above ActiveRecord example? #all will
do eager loading and combine rows, and #to_a will not. If that isn't the
issue, can you post a self contained example showing your problem?
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sequel-talk/CADGZSSd2g%3D9o9a4-LD6aiY3DhqZpon2ye-M2t9%2BBPAc%2B64Gz4A%40mail.gmail.com.