groupify icon indicating copy to clipboard operation
groupify copied to clipboard

Cannot retrieve group members in pg

Open NanoMeko opened this issue 6 years ago • 5 comments

[30] pry(main)> g.members.count (0.7ms) SELECT DISTINCT COUNT(DISTINCT "users"."id") FROM "users" INNER JOIN "group_memberships" ON "users"."id" = "group_memberships"."member_id" WHERE "group_memberships"."group_id" = $1 AND "group_memberships"."group_type" = $2 AND "group_memberships"."member_type" = $3 [["group_id", 4], ["group_type", "Group"], ["member_type", "User"]] => 1

so far so good.

[31] pry(main)> g.members.first ActiveRecord::StatementInvalid: PG::UndefinedFunction: ERROR: could not identify an equality operator for type json LINE 1: SELECT DISTINCT "users".* FROM "users" INNER JOIN "group_me... ^ : SELECT DISTINCT "users".* FROM "users" INNER JOIN "group_memberships" ON "users"."id" = "group_memberships"."member_id" WHERE "group_memberships"."group_id" = $1 AND "group_memberships"."group_type" = $2 AND "group_memberships"."member_type" = $3 ORDER BY "users"."id" ASC LIMIT $4 from /Users/.../.gem/ruby/2.3.0/gems/activerecord-5.0.6/lib/active_record/connection_adapters/postgresql_adapter.rb:657:in `prepare' \

NanoMeko avatar Aug 22 '18 02:08 NanoMeko

Same here.

drkmen avatar Aug 22 '18 07:08 drkmen

Seems to be a side-effect of how distinct works in ActiveRecord. See https://github.com/rails/rails/issues/17706

SELECT DISTINCT users.* won't work if there is a json column. The solution would be to switch to using SELECT DISTINCT ON (users.id) users.*

dwbutler avatar Aug 22 '18 07:08 dwbutler

@dwbutler has there been any resolution for this?

kcollignon avatar Jul 07 '19 21:07 kcollignon

@NanoMeko were you ever able to resolve this?

kcollignon avatar Jul 12 '19 05:07 kcollignon

Yeap, I decided to build my own group relationships with ActiveRecord 🤷🏽‍♂️

On Fri, 12 Jul 2019 at 08:56, Kevin Collignon [email protected] wrote:

@NanoMeko https://github.com/NanoMeko were you ever able to resolve this?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/dwbutler/groupify/issues/74?email_source=notifications&email_token=AAYESWKOULAHZ6UQ4RU24TDP7AMJZA5CNFSM4FQ3SXW2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZYYPNI#issuecomment-510756789, or mute the thread https://github.com/notifications/unsubscribe-auth/AAYESWL3PLOUQ6WO5E7UQX3P7AMJZANCNFSM4FQ3SXWQ .

NanoMeko avatar Jul 12 '19 14:07 NanoMeko