Questions tagged [sti]

Single Table Inheritance - a mechanism to add the principle of object-oriented inheritance onto relational database models by having child classes map onto the same table as their ancestors.

In Single Table Inheritance, types are discriminated by a field in the table that indicates what class in the hierarchy the object belongs to.

For more information see:

Single Table Inheritance - Martin Fowler - Patterns of Enterprise Application Architecture

384 questions
2
votes
1 answer

Rails: Polymorphic association needed for subclasses in STI structure?

I'm working on a hobby project and have an abstract Event model with STI subclasses Meal, Outing, Medication, etc. The Event parent model has start_time, end_time, description, etc. I want to have nested resources for the various subclasses. For…
Clay
  • 2,949
  • 3
  • 38
  • 54
2
votes
3 answers

Rails 2.3 STI return all child classes

I am using standard STI and want to create an input select on a form whose options are all child type of the parent class. So I'd like Parent.select_options to return ['Child1','Child2','Child3'] class Parent < ActiveRecord::Base # kinda what I'd…
Chris Barretto
  • 9,379
  • 3
  • 42
  • 45
2
votes
0 answers

Active Admin and STI model error: Could not find table 'categories'

Update #1: Solved! Somehow Pow did not restart it's processes, so after updates it was loading the old config files. And it was loading the wrong locale file. I deleted gems I installed recently (only from Gemfile) and restarted Pow. Then one by one…
Ivan
  • 874
  • 10
  • 32
2
votes
3 answers

Rails app using STI -- easiest way to pull these records?

I'm learning my way around Rails and am working on a sample app to keep track of beer recipes. I have a model called Recipe which holds the recipe name and efficiency. I have a model called Ingredient which is using STI - this is subclassed into…
Jim
  • 2,300
  • 1
  • 19
  • 43
2
votes
0 answers

add users based in thier role to a Single Table Inheritance user Table ( TypeORM and NestJs)

Am developing the SignUp feature and my users can be either student teacher or admin like shown in this diagram: And this is the code to implemente @Entity() @TableInheritance({ column: { type: 'varchar', name: 'type' } }) export abstract class…
2
votes
1 answer

Rails - Single Table Inheritance problems. Any solutions / alternatives

For my project management application, I am currently using Single Table Inheritance so that: Lead < Requirement Project < Requirement By which I mean to say that Lead is a Requirement and Project is a Requirement. It was okay, while I had these two…
2
votes
1 answer

Wrong sql generated by ActiveRecord for has_many :through relation with STI

Consider these models: class First < ActiveRecord::Base has_many :tags has_many :thirds, :through => :tags end class Second < ActiveRecord::Base end class Third < Second has_many :tags has_many :firsts, :through => :tags end class Tag <…
Eli B.
  • 151
  • 6
2
votes
2 answers

RoR: STI / MTI / Mixin confusion

i have a problem which is i believe basic for most of the RoR developers. In fact, it's more about "understanding" than really programming it (i have already been programming a few modules to be able to extend ActiveRecord::Base to allow easy…
Doodloo
  • 869
  • 5
  • 18
2
votes
1 answer

Rails 5.0 not fetching polymorphic association when STI is used

gem 'rails', '4.2.7.1' class Property < Accommodation has_many :attachments, as: :attached_item, dependent: :destroy end class Accommodation < ActiveRecord::Base; end class Attachment < ActiveRecord::Base belongs_to :attached_item,…
2
votes
3 answers

STI and extending Subclasses to include 'extra' columns in a database?

Maybe STI isn't what I want, and I'm open to all suggestions, but for the sake of this questions let's assume the following real world situation: You want your app to house API data for different Mail Vendors. Using STI, you have the following…
pjammer
  • 9,489
  • 5
  • 46
  • 56
2
votes
1 answer

Active Record, Polymorphic Has Many Through with STI

I'm having some trouble with a Polymorphic Has Many Through association with STI. Let me explain what I'm trying to do: Let's say I have a Contract. A Contract can have many Companies as parties to the agreement, namely, a Contract can have more…
2
votes
1 answer

Rails STI validation inheritance

I have STI models in my Rails application. The ancestor model has validations with the validates_... methods which are working fine. But I have custom validations as well, and I would like to add more different custom validations in the descendants.…
KARASZI István
  • 30,900
  • 8
  • 101
  • 128
2
votes
1 answer

Rails 5: STI With Has Many Through Association

I have searched extensively for a solution to my situation, but I can't find anything. In my application I have a Person model that only stores data about people: class Person < ApplicationRecord end Then I have a Trial model. Trials can have many…
2
votes
1 answer

rails HABTM to has many through

class QuestionSet has_and_belongs_to_many :questions, class_name: 'Exam', join_table: 'question_question_sets', foreign_key: 'question_set_id', …
2
votes
2 answers

Rails has_many STI

I've trying to implement a STI on rails 4, but I can't make it work, I've search a lot of results but none worked. Here is the problem: I have an instance class, using STI I have a subclass Car (a dummy subclass) and ScheduledInstance class. class…