0
我想通过值的关联模型来过滤我的模型。 (我想通过商店,这是产品的一个协会,来筛选变种ActiveRecord :: StatementInvalid与SQLite3 :: SQLException:没有这样的列
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: no such column: product.store_id: SELECT COUNT(*) FROM "variant_skus" INNER JOIN "products" ON "products"."id" = "variant_skus"."product_id" WHERE "product"."store_id" = ?)
为什么我收到此错误?STORE_ID肯定是我的产品表中的列。
这会引发相同的错误。 'ActiveRecord :: StatementInvalid(SQLite3 :: SQLException:no such column:product.store_id:SELECT COUNT(*)FROM“variant_skus”INNER JOIN“products”ON“products”。“id”=“variant_skus”。“product_id”WHERE “product”。“store_id”=?):' – stoerebink
Woops。把这个错误的方法。这解决了我的问题!非常感谢!! – stoerebink