我有以下架构:
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
我想查找在某个地区购买的所有购物车我设置了几个范围以使查询更具可读性但是当我尝试时:
Cart.purchased.join(:shop).merge(Shop.europe)
我收到错误:ActiveRecord::ConfigurationError: Association named 'locale' is not found; 也许你拼错了?
关于如何完成这项工作的任何想法?