I have the following model:
#models/location.rb
class Location < ActiveRecord::Base
scope :partner_locations, ->{where(partner: true)}
scope :education_locations, ->{where(education: true)}
end
Then I have the following code:
locations = Location.none
if true
#append onto that locations activerecord::relation object those locations that are partner locations
locations << Location.partner_locations
end
if true
#append onto that locations activerecord::relation object those locations that are education locations
locations << Location.education_locations
end
return locations
I would think that this code would return an activerecord::relation object with some objects inside of it. Instead it just returns: []
, just an empty Location::ActiveRecord_Relation object.
How do I append records onto this Location::ActiveRecord_Relation object?
I did some research and I see some people suggest using merge
but I don't think that is what I want. I am not doing any filtering. I only want to append on Location
objects inside that Location::ActiveRecord_Relation object so that I can then use other methods on it like: locations.order(:name)
.
.none
seems to ensure that nothing gets returned. You might use a different base scope, and only append none if no other condition is matched. - Thomas Klemm