Search code examples
rubyormsequelclass-table-inheritance

Can the ClassTableInheritance plugin for Sequel be configured to store something other than the model name as the key?


I am using the class_table_inheritance Sequel plugin for my project and I have the following models:

class Account < Sequel::Model
  plugin :class_table_inheritance
end

class TwitterAccount < Account; end
class FacebookAccount < Account; end
class GoogleAccount < Account; end

I would prefer to setup a column called 'account_type' in my Account table that is an enum with the possible values 'Twitter', 'Facebook' and 'Google' to identify what type an account is.

I don't like the idea of a column in my table that is tied to the name of my model classes. It directly ties me to the ORM I am using and prevents changing the model names.

Is there any way to provide to the class_table_inheritance plugin a key map of symbols to class name symbols just like there is the ability to provide a table map of class name symbols to table name symbols?


Solution

  • Currently, the class_table_inheritance plugin doesn't support such a feature (unlike the single_table_inheritance plugin). It shouldn't be difficult to add support for such a feature, I'll see if I can work on that soon.