开发者

It's this a bug in rails? about single table inheritance;

开发者 https://www.devze.com 2023-01-14 00:12 出处:网络
class Parent < ActiveRecord::Base end class Sub < Parent end class SubSub < Sub end >> SubSub.create :name => \'name1\'

class Parent < ActiveRecord::Base
end

class Sub < Parent
end

class SubSub < Sub
end

>> SubSub.create :name => 'name1'
>> SubSub.create :name => 'name2'
&g开发者_开发知识库t;> SubSub.create :name => 'name3'

Then


>> SubSub.all.map{|x| x.name}    # => ['name1', 'name2', 'name3']
>> Sub.all.map {|x| x.name}      # => []  # I was expected that it will show all items;
>> Parent.all.map { |x| x.name}  # => ['name1', 'name2', 'name3']

I need Sub.all to show all its subclass's items, how to make it? It's this a bug?


I tested again, and it did work when there is no 'type' column specified in the table, but fails when with the 'type' column.


There is just one table named 'parents' with 'type' column;


My Env: rails-3.0.0.beta3, ruby-1.9.2-pre


Sub.all DOES show all its subclass' items. I suggest you check your code. DEFINITELY not a bug.

0

精彩评论

暂无评论...
验证码 换一张
取 消