ruby on rails - How to exclude a collection of records with ActiveRecord? -
i have following:
= select :client, :id, user.all.map {|u| [u.username, u.id]}, include_blank: "add client username"
i'd exclude records user.all match current_user.manager_users
. point select box doesn't show users added manager_users array has_many
collection.
you that:
= select :client, :id, user.where("users.id not in (?)", current_user.manager_users.pluck(:client_id)).map {|u| [u.username, u.id]}, include_blank: "add client username"
the new stuff here:
user.where("users.id not in (?)", current_user.manager_users.pluck(:client_id)) .map{ |u| [u.username, u.id] }
the current_user.manager_users.pluck(:client_id)
part retrieve (only on db-level) client_ids of manager_users linked current_user.
hope helps!
Comments
Post a Comment