Guest User

Untitled

a guest
Dec 12th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. class Conversation < ActiveRecord::Base
  2. has_many :users_conversations
  3. has_many :users, through: :users_conversations
  4.  
  5. scope :by_participants, ->(ids) {
  6. joins(:users).where("users.id = ALL (ARRAY[?])", ids)
  7. }
  8. end
  9.  
  10. Conversation.by_participants first
  11. Failure/Error: its(:first) {is_expected.to eq(@conversation)}
  12.  
  13. ActiveRecord::StatementInvalid:
  14. PG::UndefinedFunction: ERROR: operator does not exist: uuid = text
  15. LINE 1: ...= "users_conversations"."user_id" WHERE (users.id = ALL (ARR...
  16. ^
  17. HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
  18. : SELECT "conversations".* FROM "conversations" INNER JOIN "users_conversations" ON "users_conversations"."conversation_id" = "conversations"."id" INNER JOIN "users" ON "users"."id" = "users_conversations"."user_id" WHERE (users.id = ALL (ARRAY['7c1a06c8-10c7-417f-96ea-c9c50fcaed35','8af2beca-d5f2-48d7-9857-7b5d124eaac1'])) ORDER BY "conversations"."id" ASC LIMIT 1
  19. # ./spec/models/conversation_spec.rb:19:in `block (3 levels) in <top (required)>'
  20.  
  21. HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
  22. : SELECT "conversations".* FROM "conversations" INNER JOIN "users_conversations" ON "users_conversations"."conversation_id" = "conversations"."id" INNER JOIN "users" ON "users"."id" = "users_conversations"."user_id" WHERE (users.id = ALL (ARRAY['cast (6d4ff0b3-e148-40f8-87b5-d4d03577577a as uuid)','cast (432f4f6e-5832-4831-80dc-c747b8d3e742 as uuid)']))
  23.  
  24. class Conversation < ActiveRecord::Base
  25. has_many :users_conversations
  26. has_many :users, through: :users_conversations
  27.  
  28. scope :by_participants, ->(ids) {
  29. joins(:users).where("users.id = ALL (ARRAY[?]::uuid[])", ids)
  30. # it's all about ARRAY[?]::uuid[] type cast
  31. }
  32. end
Add Comment
Please, Sign In to add comment