我有一个多态资产关系,工作正常,定义如下:
has_many :assets, :as => :assetable, :dependent => :destroy
但想要这样的东西
has_many :instore_images, :as => :assetable, class_name: "Asset", conditions: { is_instore: false }, dependent: destroy
以下作品,但自然希望将其作为一种关系:
def instore_images
Asset.where('assetable_type=? and assetable_id=? and is_instore=true','MenuItem', self.id)
end
我得到的错误是:
/Users/jt/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-3.2.17/lib/active_record/dynamic_matchers.rb:55:in `method_missing': undefined local variable or method `assetable' for #<Class:0x007fd85ed71ea8> (NameError)
我正在尝试做什么,如果是的话,语法是什么?
THX
那里没那么多,但是:
class Asset < ActiveRecord::Base
belongs_to :assetable, :polymorphic => true
attr_accessible :id, :is_instore, :asset_file_name, :asset_content_type, :asset_file_size, :asset_updated_at,
require 'digest/md5'
default_scope :order => 'position'
acts_as_list :order => 'position'