Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

thirtysixthspan/class-table-inheritance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

29 Commits

Repository files navigation

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
===========================

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 Configuration
=====================

# Migrations

create_cti_table :product, :has_children => true do |t|
t.string :description
t.decimal :price
t.timestamps
end

create_cti_table :book, :has_parent => :product, :has_children => true do |t|
t.string :author
end

create_cti_table :novel, :has_parent => :book do |t|
t.string :genre
end

create_cti_table :encyclopedia, :has_parent => :book do |t|
t.string :editor
end

create_cti_table :videos, :has_parent => :product do |t|
t.string :year
t.string :genre
end

# Models

class Product < ActiveRecord::Base
has_children
end

class Book < ActiveRecord::Base
has_parent :product
end

class Novel < ActiveRecord::Base
has_parent :product
end

class Encyclopedia < ActiveRecord::Base
has_parent :product
end

class Video < ActiveRecord::Base
has_parent :product
end


Accessing children directly
===========================

book = Book.find(1)
book.name => "Agile Development with Rails"
book.author => "Dave Thomas"
book.price => 19.00

video = Video.find(2)
video.name => "Inseption"
video.year => "2010"
video.genre => "SCI-FI"
video.price => 22.00

book = Book.new
book.name = "Hamlet"
book.author = "Shakespeare, William"
book.price => 14.00
book.save


Accessing and searching children using parent
=============================================

product = Product.find(1) # This is a Book instance.
product.author

product = Product.find(2) # This is a Video instance.
product.genre


Copyright (c) 2010-2011 Derrick Parkhurst
Copyright (c) 2010 Bruno Cordeiro, released under the MIT license

About

A plugin to make class table inheritance in Active Record.

Resources

Readme

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

Languages

  • Ruby 100.0%