README in class-table-inheritance-1.0.0 vs README in class-table-inheritance-1.1.0

- old
+ new

@@ -1,22 +1,28 @@ -ClassTableInheritance -===================== +ClassTableInheritance 1.1.0 BETA +================================ This is an ActiveRecord plugin designed to allow simple multiple table (class) inheritance. This plugin was inspired by: inherits_from plugin => http://github.com/rwl4/inherits_from and Multiple Table Inheritance with ActiveRecord => http://mediumexposure.com/multiple-table-inheritance-active-record/ +How to install +============= + +gem install class-table-inheritance + Example ======= # Migrations create_table :product do |t| t.string :description, :null => false + t.string :subtype # Only if you need access of both side see example t.decimal :price t.timestamps end create_table :book, :inherits => :product do |t| @@ -29,10 +35,11 @@ end # Models class Product < ActiveRecord::Base + acts_as_superclass # only if you want top-down access. end class Book < ActiveRecord::Base inherits_from :product end @@ -55,9 +62,21 @@ book = Book.new book.name = "Hamlet" book.author = "Shakespeare, William" book.price => 14.00 book.save + +Top-down access (Polymorphic) +============================= + + if you want to access product and get field in the subclass do you need to create a field subtype:string in superclass and ad acts_as_superclass in superclass and now you can do like this. + + product = Product.find 1 # This is a Book instance. + product.author + + product = Product.find 2 # This is a Video instance. + product.genre + if you need help contanct me: bfscordeiro (at) gmail.com . Copyright (c) 2010 Bruno Cordeiro, released under the MIT license