Rails: find elements that don't exist in the whole group -
Rails: find elements that don't exist in the whole group -
Еhis code:
message.where(sending_user_id: session[:user_id]) .order("created_at desc") .group(:thread_id) .where.not(isresponse: 1)
i homecoming messages not have column isresponse = 1
whole grouping of same thread_ids
. possible?
if illustration there column
thread_id: 1, isresponse: nil , thread_id: 1, isresponse: 1
i don't want returned.
thanks.
you can seek group by
, having
clauses:
message.where(sending_user_id: session[:user_id]) .group(:thread_id) .having(["count(case when isresponse <> ? isresponse end) = count(*)", 1])
ruby-on-rails ruby-on-rails-4 activerecord rails-activerecord
Comments
Post a Comment