{"repo":"TwilightCoders/active_record-mti","free":true,"listed":false,"github":"https://github.com/TwilightCoders/active_record-mti","clone":"git clone https://github.com/TwilightCoders/active_record-mti.git","description":"ActiveRecord support for PostgreSQL's native inherited tables (multi-table inheritance)","language":"Ruby","stars":97,"topics":["activerecord","multi-table-inheritance","postgresql"],"license":"MIT","category":"databases-storage","readme_excerpt":"ActiveRecord::MTI ActiveRecord support for PostgreSQL's native inherited tables (multi-table inheritance). Requirements - Ruby 2.7+ - ActiveRecord 5.2+ (tested through Rails 8.1) - PostgreSQL 9.4+ Installation Add to your Gemfile: How It Works PostgreSQL supports table inheritance via CREATE TABLE child () INHERITS (parent) . Child tables inherit all columns from the parent, can add their own, and rows in child tables appear in queries against the parent. Each row carries a tableoid system column identifying which physical table it belongs to. ActiveRecord::MTI uses tableoid to automatically instantiate the correct Ruby class when querying through a parent table — no discriminator column needed. Usage Models In most cases, you don't need to do anything beyond installing the gem. MTI will detect when a model maps to a PostgreSQL inherited table and handle instantiation automatically. Table Name Convention Child table names follow singular parent/plural child : Model Inferred Table Name ------------- --------------------------- Account accounts User account/users Developer account/developers Hacker account/developer/hackers Override with self.table name = '...' when needed. Queries The default SELECT includes tableoid for subclass discrimination: Migrations Child tables automatically inherit the parent's primary key and indexes. Schema Dump rake db:schema:dump produces a schema that preserves the inheritance chain: Mixing MTI and STI A model can use both. The child table can ha","default_branch":null,"files":null,"tree":[],"storefront":"/r/TwilightCoders","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/TwilightCoders/active_record-mti/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}