has_normalized_sti
==================
This extension will allow Rails STI to work a normalized type column.
For example
create_table :people, :force => true do |t|
t.string :full_name
t.integer :type_id
end
create_table :person_types, :force => true do |t|
t.string :type_name
end
class Person < ActiveRecord::Base
has_normalized_sti
end
class PersonType < ActiveRecord::Base
end
after calling has_normalized_sti:
* type - returns the name of the class of the type just as regular STI
* type= - set the type to something specific like regular STI
* normal_type - the Type object through the relation
Configuration options are:
* type_class_name - belong_to this model for the type storage
(default: #{class_name}Type)
* foreign_key - specifies the column for id of the type (default: type_id)
* type_column - specifies the column name for the type string on the types table
(default: type_name)
Override example
create_table :people, :force => true do |t|
t.string :full_name
t.integer :special_type_id
end
create_table :person_types, :force => true do |t|
t.string :special_person_type
end
class SpecialPerson < ActiveRecord::Base
set_table_name :people
has_normalized_sti :type_class_name => 'SpecialPersonType', :type_column => 'special_person_type', :foreign_key => 'special_type_id'
end
class SpecialPersonType < ActiveRecord::Base
set_table_name :person_types
end
Project
has_normalized_sti
has_normalzied_sti is a rails extension to allow Single Table Inheritance
to work with a database normalized type column.
The extension expects the STI model to have a type_id column instead of
a type column. type_id should reference a Types table containg all the possible types.
The types table will be auto populated with new types as new
subclasses are saved.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
Development
Dependencies
Project Readme