Hello! There is an ActiveRecord :: Relation of the following form:

2.2.3 :035 > g = Group.sorted.active.limit(100) => #<ActiveRecord::Relation [#<Group id: 992, login: "", hashed_password: "", firstname: "", lastname: "POS-терминалы", admin: false, status: 1, last_login_on: nil, language: "", auth_source_id: 1, created_on: "2013-02-20 10:33:36", updated_on: "2013-02-20 10:33:36", type: "Group", identity_url: nil, mail_notification: "", salt: nil, must_change_passwd: false, passwd_changed_on: nil, otp_secret_key: nil, otp_time: nil, tfa_login: nil, logout_time: nil>, #<Group id: 1255, login: "", hashed_password: "", firstname: "", lastname: "Администраторы СУБД Oracle", admin: false, status: 1, last_login_on: nil, language: "", auth_source_id: 1, created_on: "2013- 11-01 03:52:12", updated_on: "2013-11-01 03:52:12", type: "Group", identity_url: nil, mail_notification: "", salt: nil, must_change_passwd: false, passwd_changed_on: nil, otp_secret_key: nil, otp_time: nil, tfa_login: nil, logout_time: nil>, 

well, etc. Then I have a sample of the form:

 2.2.3 :036 > Group.all.find(3270) => #<Group id: 3270, login: "", hashed_password: "", firstname: "", lastname: "Отдел анализа и развития бизнес-процессов", admin: false, status: 1, last_login_on: nil, language: "", auth_source_id: nil, created_on: "2016- 07-26 14:03:24", updated_on: "2016-07-26 14:03:24", type: "Group", identity_url: nil, mail_notification: "", salt: nil, must_change_passwd: false, passwd_changed_on: nil, otp_secret_key: nil, otp_time: nil, tfa_login: nil, logout_time: nil> 

How can I exclude the results of the second sample from the first sample? Those. I need to remove the group with id 3270 from the first sample.

    1 answer 1

    In Rails 4, there is a negated condition in the query language.

     Group.sorted.active.where.not(id: 3270).limit(100) # ^^^^^^^^^^^^^^^^^^^^