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')