3
我想要使用單表繼承來查詢一個類的層次結構內的所有記錄從一個類不是單個表繼承的基類。例如,給定以下類層次。ActiveRecord多級單一表繼承查詢
class Animal < ActiveRecord::Base; end
class Dog < Animal; end
class Mutt < Dog; end
class PureBred < Dog; end
我希望能夠查詢所有的狗
dogs = Dog.all
和狗是笨蛋和純種的實例的列表。
可以這樣做嗎?我想一個概念證明在狗類的default_scope設置爲
default_scope { where(:type => ['Mutt', 'PureBred']) }
但ActiveRecord的仍然是附加的WHERE型(「狗」)