I have the following schema:
class Locale < ActiveRecord::Base
has_many :shops
# region : String
end
class Shop < ActiveRecord::Base
belongs_to :locale
has_many :carts
scope :europe, joins(:locale).where('locales.region = ?', 'Europe')
end
class Cart < ActiveRecord::Base
belongs_to :shop
scope :purchased, where('purchased_at is not null')
# purchased_at : DateTime
end
I want to find all carts that have been purchased in a certain region I have a couple of scopes setup to make the query a little more readable but when I try:
Cart.purchased.join(:shop).merge(Shop.europe)
I get the error: ActiveRecord::ConfigurationError: Association named 'locale' was not found; perhaps you misspelled it?
Any thoughts on how I can make this work?