Adds an add_extra_data method to ActiveRecord that invisibly includes an extra data table. Use with STI to keep your database clean.

Uses rspec for test.

This is an example of it in use…

Usage


Drink.all Drink.first.is_hot?

Coke.all Coke.first.is_hot? Coke.first.is_diet?

Classes


class Drink < ActiveRecord::Base

validates :is_hot, :in => [true, false]

end

class Coffee < Product end

class Water < Product end

class Coke < Product

has_extra_data
validates :is_diet, :in => [true, false]

end

schema

create_table :drinks do |t|

t.string type, :null => false
t.boolean :is_hot, :null => false

end

create_table :coke_data do |t|

t.integer :coke_id, :null => false # Foreign key here...
t.boolean :is_diet, :null => false

end

Todo


Automatically pass attributes through.