From 21bfe7f757e02998c31e1895a5796a48ca6f10ba Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Thu, 6 Feb 2014 08:42:52 -0800 Subject: [PATCH] Add examples showing class inheritance to the inheritance plugins --- lib/sequel/plugins/class_table_inheritance.rb | 14 +++++++++++--- lib/sequel/plugins/single_table_inheritance.rb | 10 +++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/sequel/plugins/class_table_inheritance.rb b/lib/sequel/plugins/class_table_inheritance.rb index 7927fab995..348688b35c 100644 --- a/lib/sequel/plugins/class_table_inheritance.rb +++ b/lib/sequel/plugins/class_table_inheritance.rb @@ -59,10 +59,18 @@ module Plugins # # # Set up class table inheritance in the parent class # # (Not in the subclasses) - # Employee.plugin :class_table_inheritance + # class Employee < Sequel::Model + # plugin :class_table_inheritance + # end # - # # Set the +kind+ column to hold the class name, and - # # set the subclass table to map to for each subclass + # # Have subclasses inherit from the appropriate class + # class Staff < Employee; end + # class Manager < Employee; end + # class Executive < Manager; end + # + # # You can also set options when loading the plugin: + # # :kind :: column to hold the class name + # # :table_map :: map of class name symbols to table name symbols # Employee.plugin :class_table_inheritance, :key=>:kind, :table_map=>{:Staff=>:staff} module ClassTableInheritance # The class_table_inheritance plugin requires the lazy_attributes plugin diff --git a/lib/sequel/plugins/single_table_inheritance.rb b/lib/sequel/plugins/single_table_inheritance.rb index e3aba19ff5..30154bf685 100644 --- a/lib/sequel/plugins/single_table_inheritance.rb +++ b/lib/sequel/plugins/single_table_inheritance.rb @@ -24,7 +24,15 @@ module Plugins # # # Use the default of storing the class name in the sti_key # # column (:kind in this case) - # Employee.plugin :single_table_inheritance, :kind + # class Employee < Sequel::Model + # plugin :single_table_inheritance, :kind + # end + # + # # Have subclasses inherit from the appropriate class + # class Staff < Employee; end + # class Manager < Employee; end + # + # # You can also use many different options to configure the plugin: # # # Using integers to store the class type, with a :model_map hash # # and an sti_key of :type