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
3
votes
1 answer

STI with Rails and Devise

i'm working on a Ruby on Rails application and using devise to authenticate user. First of all, i have these models: class User < ActiveRecord::Base devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable,…
3
votes
2 answers

Using a has_many association with a single table inheritance model in rails

I'm trying to create a simple has_many association between my Game and DLC models. The challenge I'm facing is that since there's no DLC table because of the single table inheritance, there's no way to insert a game_id. So if I were to do the…
Carl Edwards
  • 13,826
  • 11
  • 57
  • 119
3
votes
0 answers

Uninitialized constant when using nested attributes on STI subclass

I have a class/model called User which (using Single table inheritance) has a subclass called Student (among others) Student has a 'has_one' association with 'HomeAddress' which is a subclass of 'Place' My model set up: class User <…
user3711600
  • 853
  • 3
  • 12
  • 27
3
votes
1 answer

Failing Rspec only with Zeus with undefined method for existing field declared with Mongoid using STI design pattern

Using Rails 4, Zeus 0.13.3, rspec-rails edge and mongoid edge Simple STI model: File my_model.rb in /model directory class MyModel include Mongoid::Document field :my_field end File my_sti.rb in /model/my_model directory class MyModel class…
Alex
  • 4,367
  • 5
  • 29
  • 45
3
votes
2 answers

STI help. Need help refactoring my existing code

I need help implementing or breaking this into Single-Table-Inheritance (STI). I have read about it and I'm not quite sure yet if I'm going about this the right way. If you guys have suggestions to implement it. Or even if it's very different from…
index
  • 3,697
  • 7
  • 36
  • 55
3
votes
3 answers

Rails 4 Devise Multiple User Models STI

I am using Devise and Rails 4. I want to add multiple User Models(admin, usertype1, usertype2) such that they inherit from the main User Model. I have searched many posts and come to the conclusion that I may use CanCan, which I do not want, or I…
Claudiu S
  • 1,587
  • 6
  • 22
  • 40
3
votes
1 answer

Problem with one-to-many relationship with Single Table Inheritance (Rails)

I have problem with STI and relationship in ActiveRecord. I think I missed something in the class methods, but I don't know for sure. Below is my models: class User < ActiveRecord::Base has_many :advertisements end class Advertisement <…
3
votes
2 answers

Alternative to Rails Single Table Inheritance (STI)?

I have a model and table that I believe is perfectly suited to STI. My table is called Finances and has two types: Income and Expenses. Besides type there are three other columns: description, amount, and date. I'm getting very nervous using STI in…
Casey
  • 2,611
  • 6
  • 34
  • 60
3
votes
1 answer

Inheritance approach: STI? MTI? or simple polymorphic association?

I'm implementing an app to manage prodution orders. Each order has many processes (stages), including printing and bending. All processes have some common attributes as quantity and comments, and some stage-specific ones: create_table :stages do…
3
votes
1 answer

Rails STI - custom association in subclass

class Upload < ActiveRecord::Base has_many :comments end class Gallery < Upload has_many :images end class MusicAlbum < Upload has_many :audio_tracks end Should this work as expected? Will Gallery and MusicAlubm models inherit…
Wojtek Kruszewski
  • 13,940
  • 6
  • 38
  • 38
3
votes
4 answers

Rails employer and employee devise

I am trying to figure out how to structure this please help: I need users to be able to sign up as either an employer or employee. The employer basically is the company and the employees are the people employed at that job. I want to know how to…
Jab
  • 26,853
  • 21
  • 75
  • 114
3
votes
3 answers

Rails 3 using MongoDB via mongoid adapter - is there any way to share attribute specifications without using Single-Table Inheritance?

Probably a confusing title, but not sure how else to put it. Example should make it clearer. I have many different models that share many of the same attributes. So in each model I have to specify those same attributes and THEN the attributes…
Dan L
  • 4,319
  • 5
  • 41
  • 74
2
votes
3 answers

Rails STI and views reuse

I have an STI model and would like to reuse the base views for the derived model. For example, If I have Teacher < Person I would like the Teacher's view to contain the person's view fields. Is there a way to achieve this?
2
votes
0 answers

Devise + STI + Authorization

I have the following situation: My app has several types of users: Owner, Team Member, Collaborator, Client, and Guest. (the Guest type isn't relevant for this question) These are the connections between the different models: Owner belongs_to…
JeanMertz
  • 2,250
  • 2
  • 21
  • 26
2
votes
2 answers

Rails, STI and 'becomes' - f.object.errors not showing in view

My question is: why doesn't .becomes pass errors over to the new object? Isn't this the expected behaviour? I have the following single table inheritance classes in a rails app: class Document < ActiveRecord::Base validates :title, :presence =>…
Mike
  • 9,692
  • 6
  • 44
  • 61