只是在 RoR 周围玩耍,试图通过一些建模找到方法。请注意以下代码:
class Picture < ActiveRecord::Base
belongs_to :imageable, :polymorphic => true
end
class Employee < ActiveRecord::Base
has_many :pictures, :as => :imageable
end
class Product < ActiveRecord::Base
has_many :pictures, :as => :imageable
end
有没有办法通过特定图片获取产品? 我正在尝试这个,但它不起作用:
picure = Picture.last
product = Product.where(picture: picure)
它失败了:
SQLite3::SQLException: no such column: products.picture: SELECT "products".*
FROM "products" WHERE "products"."picture" IS NULL LIMIT 1```