Skip to content

Instantly share code, notes, and snippets.

@pote
Last active December 17, 2015 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pote/5550574 to your computer and use it in GitHub Desktop.
Save pote/5550574 to your computer and use it in GitHub Desktop.
Proof of concept using Class Table Inheritance
require 'sequel'
DB = Sequel.connect 'sqlite://database.db'
class Person < Sequel::Model
# has age, name, type
end
Person.plugin :class_table_inheritance, key: :type
class Chef < Person
# has recipes
end
class Scientist < Person
# has university
end
class Physicist < Scientist
# has preferred_laser
end
Sequel.migration do
change do
create_table :people do
primary_key :id
String :name
String :age
String :type
end
create_table :chefs do
foreign_key :id, :people
String :recipes
end
create_table :scientists do
foreign_key :id, :people
String :university
end
create_table :physicists do
foreign_key :id, :scientists
String :university
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment