1

class Parent < ActiveRecord::Base
end

class Sub < Parent
end

class SubSub < Sub
end

>> SubSub.create :name => 'name1'
>> SubSub.create :name => 'name2'
>> SubSub.create :name => 'name3'

然后


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

我需要 Sub.all 来显示其所有子类的项目,如何制作?这是一个错误吗?


我再次测试,当表中没有指定“类型”列时它确实有效,但在使用“类型”列时失败。


只有一个名为“父母”的表,其中有“类型”列;


我的环境:rails-3.0.0.beta3,ruby-1.9.2-pre

4

1 回答 1

0

Sub.all 确实显示其所有子类的项目。我建议你检查你的代码。绝对不是错误。

于 2010-08-31T07:32:54.777 回答