Last active
December 17, 2015 04:28
-
-
Save pote/5550574 to your computer and use it in GitHub Desktop.
Proof of concept using Class Table Inheritance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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