2

我的数据库中providers有一个名为的表,其类型列名为provider_type. provider_type可以是以下任意一种:

  • 中央
  • 赞助

我想创建一个继承自Sequel::Model被调用的类Center和一个被调用的类Sponsor,生成的方法将通过provider_type = 'center'or限定相应类的所有查询provider_type = 'sponsor'

我能够做到这一点并不是 100% 必要的,但如果可能的话,那将是理想的。

4

1 回答 1

3

You want the single_table_inheritance plugin:

class Provider < Sequel::Model
  plugin :single_table_inheritance, :provider_type
end
class Center < Provider
end
class Sponsor < Provider
end

This will work, but only if the provider_type column matches exactly "Center" or "Sponsor". If not, you might need to add a :model_map option to the plugin call. The documentation on this plugin is located at http://sequel.jeremyevans.net/rdoc-plugins/classes/Sequel/Plugins/SingleTableInheritance.html

于 2012-05-25T00:02:50.797 回答