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

Generating generic paths for STI models in Rails 4

Suppose I have a Rails 4 application that manages Widget objects, and using Simple Table Inheritance I have specialisations Widget::Foo and Widget::Bar. I would like to manage all my Widget objects through a single WidgetsController. I have the…
thomasfedb
  • 5,990
  • 2
  • 37
  • 65
0
votes
1 answer

Which relationship is good to use STI or Polymorphism?

I have read about them but still not clear to me which one I suppose to use and how. I have User model, Message model and Place model Message model: class Message < ActiveRecord::Base belongs_to :user end Messages Table: create_table…
egyamado
  • 1,111
  • 4
  • 23
  • 44
0
votes
1 answer

Rails - STI - Nested Resources - belongs_to coulmn

I'm a litte stuck unfortunately, maybe somebody can help? Thank you! I have 3 classes user,manager and driver. manager and driver are subclasses of user. driver has a belongs_to relationship with manager: class User < ActiveRecord::Base …
Tament
  • 45
  • 1
  • 1
  • 4
0
votes
1 answer

Rails Postgresql performance difference for tables with primay key vs without primary key

I would like to know if there are any performance related ups and downs for tables that has a primary key and those without primary key. I have a schema with two tables. Table Without ID create_table "site_page_views", :id => false, :force => true…
swapab
  • 2,402
  • 1
  • 27
  • 44
0
votes
1 answer

Multi-association using STI is not working

I have Employee model and TicketStatus model using STI approach on Employee model in order to have to child models 'Advisor' and 'Staff', inside my TicketStatus i am trying to achieve the following: making a relation between TicketStatus and Advisor…
0
votes
1 answer

Nullify all inheritors of the root class on destroy

Given the following: class Foo < ActiveRecord::Base; end class Bar < Foo; end class Baz < Foo; end Is there a "Rails'y" way to nullify the foreign keys for all Bars and Bazs when a class with has_many :foos is deleted? This doesn't seem to…
Kaleidoscope
  • 3,609
  • 1
  • 26
  • 21
0
votes
3 answers

STI with many types

I have a rails 4 app with STI models: # models/person.rb def Person < ActiveRecord::Base end # models/director.rb def Director < Person end # models/actor.rb def Director < Person end But because one person can be an actor and an director…
innerwhisper
  • 1
  • 1
  • 2
0
votes
1 answer

Rails, STI and nested resources

I have the models foo1, foo2, foo3 and foo4, which are subclasses of foo. And I have models like bar and baz. Models bar and baz contain objects of type foo and of all its children. Also, each type has an action called next. Now I must setup routes…
pudiva
  • 274
  • 5
  • 15
0
votes
2 answers

.NET StillImage, RegisterLaunchApplication

I am trying to register my application for scanner's scanning action. Following code should do that: public class Class1 { [ComImport] [Guid("641BD880-2DC8-11D0-90EA-00AA0060F86C")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] …
user2126375
  • 1,594
  • 12
  • 29
0
votes
3 answers

Rails make an STI backed form post to the correct path

I am using STI in my rails app: class Project < ActiveRecord::Base end class Video < Project end I've got the following routes: resources :projects resources :videos, :controller => "projects", :type => "video" And when I rake my routes I see…
stephenmurdoch
  • 34,024
  • 29
  • 114
  • 189
0
votes
1 answer

Rails 4 nested attributes and sti model update_attributes creates new records

i've a rails 4 instance running with a pages model which has different types of page contents like PageContent::Text which inherits from PageContent. in my form i render all my @page.page_contents as you can see in the form snippet.. if i update my…
Oliver
  • 801
  • 13
  • 26
0
votes
0 answers

Rails: STI with roles and HABTM

In the app I am working with here are the User models... class User < ActiveRecord::Base has_and_belongs_to_many :roles end class Athlete < User end class HighSchoolCoach < User end A user can have a role of SchoolAdmin which grants them…
dennismonsewicz
  • 25,132
  • 33
  • 116
  • 189
0
votes
1 answer

ActiveAdmin STI error on show action but not edit

I am setting up an active_admin app and have the following STI structure class Organization < ActiveRecord::Base attr_accessible :name, :type end class Contractor < Organization def self.model_name return Organization.model_name …
Tyrone Wilson
  • 4,328
  • 2
  • 31
  • 35
0
votes
2 answers

Rails ownership chain and STI

Given the following tables: users organizations accounts owner_id owner_type profiles Where Accounts can be owned by either a User or an Organization, and each Account has exactly one Profile, is it possible to do STI in Rails on the Profile…
kid_drew
  • 3,857
  • 6
  • 28
  • 38
0
votes
0 answers

What is the best way to configure inheritance in this scenario?

So here is the scenario. Lets say that you have 10 different suppliers that provide products that you sell. Now for this scenario assume that each supplier has their own methods for order processing and each require their own class. This is a big…
Tom Rossi
  • 11,604
  • 5
  • 65
  • 96