簡體   English   中英

ActiveRecord :: StatementInvalid與SQLite3 :: SQLException:無此類列

[英]ActiveRecord::StatementInvalid with SQLite3::SQLException: no such column

我正在嘗試通過關聯模型的值來過濾模型。 (我正在嘗試按商店過濾我的變體,這是產品的關聯。

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:從“ variant_skus”中選擇COUNT(*)INNER JOIN“ products”在“ products”上。“ id” =“ variant_skus”。“ product_id”在“”產品”。“ store_id” =?)

為什么會出現此錯誤? Store_id絕對是我的產品表上的一列。

該表已定義,但是由於它被稱為products ,因此無法找到帶有product前綴的列。 您可以where('products.store_id = ?', store_id)方法中使用where('products.store_id = ?', store_id)


[英]#<ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: users.sender_id:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM