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
3 answers

Should I namespace STI models?

I have the following models: module Core class Conditioner include Mongoid::Document field :operator, type: String, default: '' # can be !=, ==, <, >, <=, >=, = end end module Core class Count < Conditioner field :threshold,…
Pierre-Louis Gottfrois
  • 17,561
  • 8
  • 47
  • 71
0
votes
1 answer

Access to attributes of associated class (STI) Rails 3

I have a such model class Group < ActiveRecord::Base has_many :people has_one :leader attr_accessible :name end class Person < ActiveRecord::Base belongs_to :group end class Leader < Person belongs_to :group attr_accessible…
Maria
  • 79
  • 7
0
votes
1 answer

rails: create posts using STI

I am using single tablable inheritance(STI) to create different types of articles. But now I have problem while creating articles.(I can do it only in console). Here are my models Article.rb class Article < ActiveRecord::Base attr_accessible…
lucy
  • 65
  • 8
0
votes
0 answers

Making a parent class unusable in single table inheritance (Rails)

I have a PhoneNumber class (below) that I want to act as the parent class to child classes using single table inheritance. These children include MobileNumber, HomeNumber, Fax, Pager, etc. I would like to force every PhoneNumber class to be a…
0
votes
1 answer

rails STI subclass returns superclass

I have a STI class hierarchy like so: Producer, Partner, Freelancer < Statusowner < Contact When I call e.g. Partner.all I see rails producing this: SELECT "contacts".* FROM "contacts" WHERE "contacts"."type" IN ('Partner', 'Producer', 'Partner',…
0
votes
2 answers

Rails callback not firing when building nested STI resource through an association

Take the following for example: class Foo < AR::Base has_many :bars, :as => :barable, :dependent=> :destroy accepts_nested_attributes_for :bars, :allow_destroy => true end class Bar < AR::Base belongs_to :barable, :polymorphic => true …
user1032752
  • 751
  • 1
  • 11
  • 28
0
votes
1 answer

Scopes doesn't work with STI

I want to do STI in Rails. class AbstractUser < ActiveRecord::Base self.table_name = 'users' belongs_to :organization, :inverse_of => :users # reporter user has_many :requests, :dependent => :destroy # startup user has_many …
ciembor
  • 7,189
  • 13
  • 59
  • 100
0
votes
1 answer

Rails MySQL query with Single Table Inheritance N+1 issue

I am trying to find all users that signed up during a given period of time to the ActionMovie plan. I am running into an N+1 problem and it's taking me a very long time to get the number of new signups. I was wondering if there was any creative…
BC00
  • 1,589
  • 3
  • 29
  • 47
0
votes
2 answers

Setting up a parent and child model but child has it's own columns

I am trying to set up a structure with a parent that has some attributes and children models that inherit those attributes as well as maintain their own. Ideally I'd like a setup of class Parent attr_accessible :some_attribute, some_attribute2,…
0
votes
1 answer

Rails - 1 User model, but 2 Profile type models?

Just finished Michael Hartl's Tutorial, so this is kind of a newbie question. But, after lots of searching, I have not yet been convinced of a good solution for this: I have a single User model that captures standard attributes (name, email,…
0
votes
1 answer

ruby-on-rails: creating models with single table inheritance?

I have a couple of models in my system: User Reputation Post Reputation Response Reputation (similar to SO). So, they are share some basic code: Incrementing and decrementing values a unique_id belonging to the three object that the…
cbrulak
  • 15,436
  • 20
  • 61
  • 101
0
votes
1 answer

Rails STI build relation

I'm using STI (correctly, I promise!) for one relation of an object: class Walrus < ActiveRecord::Base has_one :bubbles end class Bubbles < ActiveRecord::Base belongs_to :walrus before_save :set_origin private def set_origin …
Chris
  • 11,819
  • 19
  • 91
  • 145
0
votes
3 answers

Rails 3 Unexpected Callback Behavior in STI model

Can't figure out why this would be happening: class Foo < ActiveRecord::Base belongs_to :belongable, :polymorphic => true def after_save if belongable.kind_of?(User) send(:some_method) end end end class Bar < Foo def…
user1032752
  • 751
  • 1
  • 11
  • 28
0
votes
0 answers

Rails: delete polymorphic STI has_many through association fails

I have a model called User which has many "taxonomies" associated through a Classification model. One of these taxonomies is a model called Topic (inheriting from Taxonomy). My model User is also called a "classifiable". EDIT: Added more models to…
0
votes
1 answer

How do I mass assign from a form_tag param using STI

I am using STI to create a app which has a User parent and two children Employer and Jobseeker. The relationships have been setup and tested. I want to use STI to store Employer Users and Jobseeker Users into Postgres using only 1 users controller.…
Vishal Sakaria
  • 1,367
  • 1
  • 17
  • 28