Skip to content

jmoline/sti_extension

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StiExtension
============

This plugin is not yet ready for general use!

Let's say you want to use STI, but you don't so much like the "single" part. It feels a little clunky to add every possible field for all of the subclasses into one table. This plugin allows you to normalize your database without losing the ease of Rails' STI implementation. Simply add the method call to an ActiveRecord model, passing the method the name of another ActiveRecord model and voila! The plugin uses delegation, an after_save callback, and (an unfortunate hijacking of) the initialize method to make it appear to the developer that the 2 models are, in practice, one. This makes it possible for forms and new and create calls to treat the submodel's fields as though they were a part of the STI model.

StiModel.new(:model_field1 => "something", :model_field2 => "something_else", :submodel_field1 => "something_else_again")


Example
=======

class Yadda < ActiveRecord::Base

  is_extended_by YaddaYadda

end

ToDo
====

Tests!
Implement the after_save callback
Add support for polymorphic submodels
Find an alternative to completely hijacking the initialize method

Copyright (c) 2009 James Moline, released under the MIT license

About

A plugin that enables the programmer to easily extend an STI subclass with another model (that, in theory, contains subclass specific fields), allowing the DB to be more normalized, while not giving up the ease and benefits of Rails STI.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors