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.

sti
Filter by
Sorted by
Tagged with
1 vote
2 answers
145 views

Devise and STI, created user not being logged in

can someone tell me why my newly created user is not automatically logged in please? (Rails 3.2.2, Devise 3.2.1) user.rb class User < ActiveRecord::Base # Include default devise modules. Others ...
pingu's user avatar
  • 8,767
0 votes
3 answers
627 views

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 ...
innerwhisper's user avatar
0 votes
1 answer
270 views

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 ...
pudiva's user avatar
  • 274
0 votes
2 answers
389 views

.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")] [...
user2126375's user avatar
  • 1,614
0 votes
3 answers
104 views

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 => "...
stephenmurdoch's user avatar
3 votes
2 answers
223 views

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 ...
index's user avatar
  • 3,697
0 votes
1 answer
1k views

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 ...
Oliver's user avatar
  • 841
1 vote
1 answer
330 views

Single Table Inheritance(STI) with Single Controller and Nested Resources: polymorphic_path doesn't match route-generated path

So that's a mouthful. Let's assume that you're a vehicle manufacturer and you want a webapp for stuff. Part of that webapp is used for your designers to collaborate on their designs. You design ...
Leanan's user avatar
  • 732
0 votes
0 answers
85 views

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 ...
dennismonsewicz's user avatar
0 votes
1 answer
718 views

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....
Tyrone Wilson's user avatar
7 votes
2 answers
3k views

Routes, path helpers and STI in Rails 4.0

This is driving me crazy! I have the two models Lion and Cheetah. Both inherit from Wildcat. class Wildcat < ActiveRecord::Base; end class Lion < Wildcat; end class Cheetah < Wildcat; end ...
Hiasinho's user avatar
  • 656
0 votes
2 answers
66 views

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, ...
kid_drew's user avatar
  • 3,925
1 vote
2 answers
2k views

Creating form for STI Model

Referring to this post: Rails: Deal with several similar model classes? Using combination of STI and Store feature to organize very similar models. "Declare a base model for Student with a text ...
Katie H's user avatar
  • 2,283
32 votes
1 answer
12k views

Testing simple STI with FactoryGirl

I have got a class, that is the base of some other classes that specializes the behavior: class Task < ActiveRecord::Base attr_accessible :type, :name, :command validates_presence_of :type, :...
Mark's user avatar
  • 7,567
0 votes
0 answers
46 views

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 ...
Tom Rossi's user avatar
  • 11.8k
0 votes
3 answers
1k views

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 ...
Pierre-Louis Gottfrois's user avatar
0 votes
1 answer
90 views

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 &...
Maria's user avatar
  • 79
3 votes
3 answers
3k views

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 ...
Claudiu S's user avatar
  • 1,607
2 votes
1 answer
1k views

Rails STI: Subclass methods not being called as expected

I have this STI implementation: class Instruction < ActiveRecord::Base def get_view return "I'm a pseudo abstract base method!" end end class SCreateWebPage < Instruction def ...
Alex Edelstein's user avatar
0 votes
1 answer
427 views

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 ...
lucy's user avatar
  • 65
2 votes
2 answers
2k views

Single Table Inheritance in Rails 4

I'm trying to implement a somewhat simple STI in Rails 4, but there's something I can't yet manage to achieve. I have the following classes: class Person < ActiveRecord::Base end class ...
Fabian Silva's user avatar
0 votes
0 answers
360 views

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 ...
philjay's user avatar
0 votes
1 answer
334 views

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 "...
Kostas Georgokitsos's user avatar
1 vote
0 answers
209 views

Eager load associations on STI subclasses when joining to parent class with Doctrine

Product has a oneToMany relationship with Deliverable. Using STI I have defined several types of deliverable such as DigitalDeliverable and MerchDeliverable which subclass Deliverable. ...
Peter Horne's user avatar
  • 6,690
2 votes
1 answer
403 views

Rails 3 STI: removing association in subclass

So I'm currently working on a new version of a JSON API which needs to be backwards compatible. I have the following models set up: class Student # this is a student of type "version 1" has_one :...
Vapire's user avatar
  • 4,578
0 votes
2 answers
395 views

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 &...
user1032752's user avatar
1 vote
0 answers
195 views

require impressionist in initializer

tl;dr; In development env, I want to preload the model with is_impressionable from initializer (since it is using STI). But an error occurred during preload undefined method is_impressionable. I've ...
mmhan's user avatar
  • 731
1 vote
1 answer
115 views

Sharing attributes between models - Datamapper

I have two models that share some of the same attributes so I wanted to setup a single table inheritance structure. After doing some research, I found out that I can use module to achieve the same by ...
pwc's user avatar
  • 161
0 votes
1 answer
997 views

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, :...
ciembor's user avatar
  • 7,267
8 votes
4 answers
6k views

STI in Rails: How do I change from a superclass to a subclass without accessing the "type" attribute directly?

So, I have the following: class Product < ActiveRecord::Base # Has a bunch of common stuff about assembly hierarchy, etc end class SpecializedProduct < Product # Has some special stuff ...
Jamie's user avatar
  • 93
1 vote
2 answers
377 views

Rails 3 devise_for and STI

I have the following models: User Athlete < User Coach < User In my routes, I have the following: devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks", ...
dennismonsewicz's user avatar
1 vote
3 answers
75 views

Rails3 route STI Models

I have Vehicle and STI models Car and Motorcycle. I have currently routes configured as below: resources :vehicles resources :cars resources :motorcycles However, I'm thinking it would look ...
mmhan's user avatar
  • 731
1 vote
4 answers
372 views

Single Table Inheritance with Conditions

I have model User and model Recruiter. Currently, these are two separate tables, but I want to make them one. Current: User: id, username, password, name Recruiter: id, user_id Ideal: User: id, ...
Josh Brody's user avatar
  • 5,273
0 votes
1 answer
255 views

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 ...
BC00's user avatar
  • 1,639
1 vote
0 answers
118 views

Access belongs_to on a Mongoid::Document subclass

I have a model 'Index' as: class Index include Mongoid::Document belongs_to :project end Another model PercentileRankIndex inherits Index class PercentileRankIndex < Index def self....
Nitish Upreti's user avatar
0 votes
2 answers
285 views

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 ...
JustNeph's user avatar
  • 761
1 vote
1 answer
425 views

Rails: Creating Wrong Table Name With a Namespaced STI

I have a model which uses STI: class Contributor::Name < Contributor::NameBase ... end From this model: class Contributor::NameBase < ActiveRecord::Base ... end Whenever Contributor::...
nullnullnull's user avatar
  • 8,119
1 vote
0 answers
325 views

Rails: Undefined Method Error for Namespaced, STI-Inherited Class

I have an after_create callback in my Tag model: def auto_vote params = parametrize_media_tag(media_tag) Tag::Vote.cast_vote(params) end Which gives me this error: undefined method `cast_vote' ...
nullnullnull's user avatar
  • 8,119
1 vote
1 answer
3k views

Rails: Get the Class Name of a Child Class in a Parent Class Method

I have a STI table (Vote) with many children (Tag::Vote, User::Vote, Group::Vote, etc). All the children classes share a very similar method that looks like this: def self.cast_vote(params) value = ...
nullnullnull's user avatar
  • 8,119
0 votes
1 answer
686 views

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 ...
mattq's user avatar
  • 89
1 vote
1 answer
2k views

rails- what value to use for type column? (STI)

Given a table of users: create_table :users do |t| t.string :email t.string :website t.string :type end Class User < ActiveRecord::Base and subscribers that inherit from User Class ...
Michael Durrant's user avatar
2 votes
1 answer
715 views

STI, delegate and becomes

I have some STI setup like this: class Document < ActiveRecord::Base attr_accessible :name, description # Basic stuff omitted end class OriginalDocument < Document has_many :...
pdu's user avatar
  • 10.4k
2 votes
2 answers
562 views

Rails STI with devise and rolify error

I'm developing a Rails 3.2.13 app using Devise and Rolify, and I need to have 3 user types as follows: class User < ActiveRecord::Base rolify ... end class UserTypeOne < User .... end ...
bigardone's user avatar
  • 174
4 votes
1 answer
772 views

rails change path of partial collection rendering

I have an STI relationship where a conversation is composed of both messages and images. Now when I go to render them i use: <%= render conversation %> which works perfect. It finds the given ...
Mike Silvis's user avatar
  • 1,309
0 votes
1 answer
1k views

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 ...
Chris's user avatar
  • 12.1k
0 votes
3 answers
347 views

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(:...
user1032752's user avatar
1 vote
1 answer
309 views

Copy model instances in Rails with single table inheritance

I have BaseProject, ProjectTemplate and Project class ProjectTemplate << BaseProject; end class Project << BaseProject; end I would like to copy project_template attributes to a new ...
bonyiii's user avatar
  • 2,853
0 votes
0 answers
453 views

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 ...
Jonathan Roy's user avatar
0 votes
1 answer
138 views

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 ...
Vishal Sakaria's user avatar
0 votes
1 answer
585 views

ElasticSearch with Tire doesn't include custom analyzer with STI model

I have an STI model which I want to be searchable with ElasticSearch and Tire. The issue I am having is when Tire creates the mappings it seems to ignore my custom analyzers for the second model. ...
user1340515's user avatar

1
4
5
6 7 8