Sequel single table inheritance

Posted by Moser on 20 Oct 2009

Sequel’s STI is not so well documented as ActiveRecord’s is. Because it cost me about 20 minutes to find out about it’s syntax, I post a little example.

class A < Sequel::Model
  plugin :single_table_inheritance, :object_type
end

class B < A
end

The second argument is the name of the column to be used to store the class name in DB. Don’t use ‘type’ here, it collides with Ruby’s Object#type. This works with version 3.5.0 and should work with any version >= 2.12.0.

blog comments powered by Disqus