How would I add "OR" to this where statement when setting my instance variable in a Rails controller?
@activities = PublicActivity::Activity.order("created_at DESC").where(owner_type: "User", owner_id: current_user.followed_users.map {|u| u.id}).where("owner_id IS NOT NULL").page(params[:page]).per_page(20)
I want to set @activities to records where owner_id is equal to either current_user.id or the current_user.followed_users. I tried adding .where(owner_id: current_user.id)
but that seems to negate the entire query and I get no results at all. The query looked like this after I added to it:
@activities = PublicActivity::Activity.order("created_at DESC").where(owner_type: "User", owner_id: current_user.followed_users.map {|u| u.id}).where(owner_id: current_user.id).where("owner_id IS NOT NULL").page(params[:page]).per_page(20)
How can I add an OR condition so that I pull records where owner_id is either current_user or current_user.followed_users?
Thanks!
IN
ActiveRecord::Associations::CollectionProxy
, right? :-)map
is method of Array, I think it will change this CollectionProxy and return Array.map
will return an array, as implemented inEnumerable
, but that doesn't mean thatfollowed_users
is an array. :-)