Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

activerecord-mti

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

activerecord-mti

  • 0.0.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

ActiveRecord MTI (Multiple Tables Inheritance)

This gem allows you to make models which attributes are distributed by two tables.

Installation

Add to your Gemfile:

gem 'activerecord-mti'

Usage

Consider the following DB schema:

create_table :subjects do |t|
  t.string :name
end

create_table :roles do |t|
  t.integer :subject_id
  # MTI fields
  t.integer :role_id
  t.integer :role_type
end

create_table :employees do |t|
  t.string :appointment
end

create_table :clients do |t|
  t.string :address
end

and corresponding models:

class Subject < ActiveRecord::Base
  has_many :roles
end

class Role < ActiveRecord::Base
  mti_base  
  belongs_to :subject
end

class Employee < ActiveRecord::Base
  mti_implementation_of :role
end

class Client < ActiveRecord::Base
  mti_implementation_of :role
end

Have fun with roles as base and implementation objects at the same time:

Subject.first.roles # => [#<Employee …>, #<Client …>]
Employee.first.subject # => #<User …>
Role.where(role_type: Client).first.address # => String
Client.first.role # => #<Role …>
Client.first.role_id == Client.first.role.id # => true
Client.create!(:address => 'somewhere').role # => #<Role …>

Testing

bundle exec rspec spec

FAQs

Package last updated on 25 Jun 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc