Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot retrieve group members in pg #74

Open
NanoMeko opened this issue Aug 22, 2018 · 5 comments
Open

Cannot retrieve group members in pg #74

NanoMeko opened this issue Aug 22, 2018 · 5 comments
Labels

Comments

@NanoMeko
Copy link

[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'
\

@drkmen
Copy link

drkmen commented Aug 22, 2018

Same here.

@dwbutler
Copy link
Owner

Seems to be a side-effect of how distinct works in ActiveRecord. See rails/rails#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 dwbutler added the bug label Aug 22, 2018
@kcollignon
Copy link

@dwbutler has there been any resolution for this?

@kcollignon
Copy link

@NanoMeko were you ever able to resolve this?

@NanoMeko
Copy link
Author

NanoMeko commented Jul 12, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants