1
class Item < ActiveRecord::Base
belongs_to :rulable, :polymorphic => true
end
class foo < ActiveRecord::Base
has_many :items, :as => rulable
end
class bar < ActiveRecord::Base
has_many :items, :as => rulable
end
找到属于foo的物品的最佳方法是什么?我目前使用的是这样的:如何找到多态关系
f = Foo.find 1
Item.find_by_rulable_id_and_rulable_type(f, 'Foo')