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

Popular posts from this blog

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -