【发布时间】:2016-12-08 06:10:42
【问题描述】:
我正在尝试按关联模型的值过滤我的模型。 (我正在尝试按商店过滤我的变体,这是产品的关联。
class Variant < ActiveRecord::Base
belongs_to :product
def self.by_store_id(store_id)
where(:product => {:store_id => store_id})
end
###
class Product < ActiveRecord::Base
belongs_to :store
class Store < ActiveRecord::Base
has_many :products
每次我尝试这个,我都会收到这个错误:
ActiveRecord::StatementInvalid (SQLite3::SQLException: 没有这样的列: product.store_id: SELECT COUNT(*) FROM "variant_skus" INNER JOIN “产品”在“产品”上。“id”=“variant_skus”。“product_id”在哪里 "product"."store_id" = ?)
为什么会出现此错误? Store_id 绝对是我产品表上的一列。
【问题讨论】:
标签: ruby-on-rails activerecord sqlite