I see, sorry about that. I'm trying to put together GraphQL query resolver 
for members. So i need a pagination, total count etc. information.

nodes = current_account.members_dataset.eager_graph(member_integrations: 
[:member_integration_fields]).order(*array_order)

nodes.count # returns 600, which is incorrect
nodes.all.count # returns 100, but correct if i'm wrong, it's an array 
count 

nodes.offset(0).limit(50).count # returns 50, but 
nodes.offset(0).limit(50).pluck(:id).uniq.count returns 8
nodes.offset(0).limit(50).all.count # returns 8

So i'm unable to fetch the right count of members + create total count (not 
using array count).

Thank you,

Michal

Dne čtvrtek 29. července 2021 v 16:48:14 UTC+2 uživatel Jeremy Evans napsal:

> 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/83fc6718-2115-40c0-801f-59dc8df9eda8n%40googlegroups.com.

Reply via email to