我有一个使用单表继承的纸牌游戏应用程序。我有一个, 和一个带有 columnclass Card
的数据库表,以及一些子类(包括and ,为了论证)。cards
type
Card
class Foo < Card
class Bar < Card
碰巧的是,Foo
是游戏原始印刷中的Bar
牌,而是扩展包中的牌。为了使我的模型合理化,我创建了一个目录结构,如下所示:
app/
+ models/
+ card.rb
+ base_game/
+ foo.rb
+ expansion/
+ bar.rb
并修改 environment.rb 以包含:
Rails::Initializer.run do |config|
config.load_paths += Dir["#{RAILS_ROOT}/app/models/**"]
end
但是,当我的应用从数据库中读取卡片时,Rails 会抛出以下异常:
ActiveRecord::SubclassNotFound (The single-table inheritance mechanism failed to locate the subclass: 'Foo'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Please rename this column if you didn't intend it to be used for storing the inheritance class or overwrite Card.inheritance_column to use another column for that information.)
是否有可能完成这项工作,或者我注定要使用平面目录结构?