English 中文(简体)
Sequel 中的单表继承:: 模式 (Ruby ORM)
原标题:Single Table Inheritance in Sequel::Model (Ruby ORM)

我在数据库中有一个名为 provideers 的表格,其类型栏名为 provider_type provider_type 可以是以下之一:

  • center
  • sponsor

我想创建一个从 Sequel:: Model 继承的类别,称为 Center 和名为 Sponsor 的类别。 由此得出的方法将覆盖相应类别的所有查询,其范围为 prover_type=center provider_type=赞助人

我这样做并非100%必要,但如果可能的话,那将是理想的。

最佳回答

您想要单位表继承插件 :

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

这将有效, 但只有在提供方类型列完全匹配“ Center” 或“ sponsor” 时才会有效 。 否则, 您可能需要在插件呼叫中添加一个 : model_ map 选项。 此插件上的文档位于 < a href=> http:// sequel.jeremeyevans. net/ rdoc- plugins/ class/ Sequel/ Plugins/ Single TableInheritance. html" rel=“ nofol” >http:// sequel.jeemyevans. net/rdoc- plugins/ class/ Sequel/ Plugins/ Single TableInheritance. html

问题回答

暂无回答




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签