README in class-table-inheritance-1.2.1 vs README in class-table-inheritance-1.3.0
- old
+ new
@@ -1,11 +1,19 @@
+Change log
+==========
+
+* Now you can inherits from and to modules like inherits_from 'Module::Model', see the the name of field
+must be module_model_id:integer thanks for Marc Remolt (https://github.com/mremolt).
+* Unit test
+
+
Versions
========
If you are using Rails 2.3.8 or other version < 3, you have to use the version 1.1.x of this plugin, for Rails 3 you need to use the version 1.2.x or master of this plugin.
-ClassTableInheritance 1.2.0
+ClassTableInheritance 1.2.1
===========================
This is an ActiveRecord plugin designed to allow
simple multiple table (class) inheritance.
@@ -21,26 +29,27 @@
Example
=======
# Migrations
- create_table :product do |t|
+ create_table :products 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|
+ create_table :books, :inherits => :product do |t|
t.string :author, :null => false
end
create_table :videos, :inherits => :product do |t|
t.string :year, :null => false
t.string :genre, :null => false
end
+
# Models
class Product < ActiveRecord::Base
acts_as_superclass # only if you want top-down access.
end
@@ -67,9 +76,31 @@
book = Book.new
book.name = "Hamlet"
book.author = "Shakespeare, William"
book.price => 14.00
book.save
+
+
+Module inheritance
+==================
+# Migrations
+
+create_table :mod_users do |t|
+ t.string :name, :null => false
+end
+
+create_table :managers, :inherits => 'Mod::User' do |t|
+ t.string :salary, :null => false
+end
+
+# Models
+
+class Mod::User < ActiveRecord::Base
+end
+
+class Manager < ActiveRecord::Base
+ inherits_from 'Mod::User'
+end
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.