single-table-inheritance

How do I so a select input for a STI column in a Rails model?

I have a model with single-table inheritance on the type column: class Pet < ActiveRecord::Base TYPES = [Dog, Cat, Hamster] validates_presence_of :name end I want to offer a <select> dropdown on the new and edit pages: <% form_for @model do |f| %> <%= f.label :name %> <%= f.text_input :name %> <%= f.label :type %> <%= f....

inheritance issues with propel 1.5.2

In propel 1.3 and 1.4 the following inheritance structure worked fine. table name="payment_method" baseClass="rwf.lib.SymmetricEncryptedObject"> column name="id" type="INTEGER" required="true" autoIncrement="true" primaryKey="true"/> column name="discriminator" type="INTEGER" inheritance="single" required="true"> in...

Controller inheritance in Ruby on Rails -- model and controller access in parent class

I am using single table inheritance in StudentHours and TeacherHours, which have a parent Hours. The model code is mostly in hour.rb, and very little in student_hour.rb and teacher_hour.rb Now I have realized that most of the controller code is duplicate as well, so I've created a hours_controller to be the parent of students_controlle...

How does the Rails' single table inheritance works?

I have a user table, and a teacher that I newly created. The teacher is sub class of user, so, I use scaffold generator to generate the teacher table, than, I modify the model to do teacher is subclass of user. After all that, I did a db:migrate. Then, I go to http://localhost:3000/teachers/new It shows an error: undefined method `te...

Hibernate, single table inheritance and using field from superclass as discriminator column

I have following kinds of classes for hibernate entity hierarchy. I am trying to have two concrete sub classes Sub1Class and Sub2Class. They are separated by a discriminator column (field) that is defined in MappedSuperClass. There is a abstract entity class EntitySuperClass which is referenced by other entities. The other entities shoul...

Changing type of ActiveRecord Class in Rails with Single Table Inheritance

I have two types of classes: BaseUser < ActiveRecord::Base and User < BaseUser which acts_as_authentic using Authlogic's authentication system. This inheritance is implemented using Single Table Inheritance If a new user registers, I register him as a User. However, if I already have a BaseUser with the same email, I'd like to ...

Should you use single table inheritance or multiple tables that are union-ed in a view?

Let's say you have a notes table. The note can be about a particular account, orderline or order. Notes that are about the account do not apply to any specific orderline or order. Notes that are about the orderline also apply to the parent order and the account that is attached to the order. Notes that are on the order also apply to t...

Creating the same model from multiple data sources

This is mostly of a design pattern question. I have one type of model that I'm going to get the data to create them from multiple sources. So for example one record my be created from an API where another is created via screen scraping with Nokogiri. My issue lies in how best to abstract out these different data sources. Right now I...

Is this a good design in hibernate?

Hi all, i have a parent entity Service and a child ExtendedService in a SINGLE_TABLE inheritance. A third entity ServiceCollector need to include both entites Service and ExtendedService. This is a fixed requirement, and with this design i can realize it using polymorphism. THE PROBLEM: Very often i need to retrieve ONLY the parent cla...

Using a navigation property as discriminator in a TPH inheritance scenario in Entity Framework 4

Hi, I am trying to create a TPH inheritance hierarchy using foreign keys / navigation properties as discriminators and I am having some trouble getting it right. I have the following entities: Person: Id (int) Name (nvarchar) PlaneId (int) CarId (int) Car: Id (int) Name (nvarchar) Plane: Id (int) Name (nvarchar) wi...

It's this a bug in rails? about single table inheritance;

class Parent < ActiveRecord::Base end class Sub < Parent end class SubSub < Sub end >> SubSub.create :name => 'name1' >> SubSub.create :name => 'name2' >> SubSub.create :name => 'name3' Then >> SubSub.all.map{|x| x.name} # => ['name1', 'name2', 'name3'] >> Sub.all.map {|x| x.name} # => [] # I was expected that it ...

Is a polymorphic association appropriate here?

Here's what I'm thinking: class Widget < ActiveRecord::Base has_one :widget_layout end class WidgetLayout < ActiveRecord::Base belongs_to :widget belongs_to :layoutable, :polymorphic => true end class InformationalLayout < WidgetLayout has_one :widget_layout, :as => :layoutable end class OneWayCommunicationLayout < WidgetLayo...

How many classes is too many? Rails STI

I am working on a very large Rails application. We initially did not use much inheritance, but we have had some eye opening experiences from a consultant and are looking to refactor some of our models. We have the following pattern a lot in our application: class Project << ActiveRecord::Base has_many :graph_settings end class Graph...

Join Model + STI + Polymorphic Associations - Can ActiveRecord not do this?

The question is at the bottom, but the code describes the bulk of it :) Here's the base of the code, shortened to get to the core of it: ActiveRecord::Base.class_eval do def self.joins(*others) has_many :parent_join_models, :as => :child has_many :child_join_models, :as => :parent options = others.extract_options! th...

Rails Single Table Inheritance using Foreign Key (ID)

Hi, I have to model an association structure and the association is divided into divisions/subdivisions/sections etc. So I've created a simple Entity-Attribute Model: I'd like to use rail's single-table-inheritance but it seems like this works only if the type column is a string. My question is how to achieve this with my approach? S...

Implementing STI where the parent class doesn't have a controller of its own its just a model and has a relationship with other models. Rails STI

I have the following scenario class XYZ < ActiveRecord::Base has_many :abcs end class ABC < ActiveRecord::Base belongs_to :xyz end class A < ABC end class B < ABC end class C < ABC end The model ABC doesn't have any controller, or view. Data related to ABC will be inserted from the XYZ views and controllers. The user sets a type v...

Is Single-Table Inheritance the right solution for my Rails problem?

Greetings, all, I'm working on an application in Ruby on Rails where we need to keep track of a bunch of external services for each user (for example, Facebook, MySpace, Google, SalesForce, Twitter, WordPress, etc) that the app will access on behalf of the user. For some services, we will need to store an (encrypted) username and passwo...

How to write unit tests for STI associations Ruby on Rails

What steps should you use when in a need to write unit tests for STI associations. I am completely confused. Please provide some suggestions or links to some tutorials. Thanks in advance ...

Can a Discriminator Column be part of the Primary Key in Doctrine2?

I'm using Single Table Inheritance in Doctrine2 to store OAuth credentials for multiple services. I'd like to use the service's id as the primary key; however, that's not unique across all services. I've setup the database to use the discriminator column and the service's id as the primary key, but I can't find a way to make Doctrine u...

Rails belongs_to and single table inheritance not behaving

I have a Bike model and a Component model. Several models inherit from Component: Frame, Chain, Crankset etc. When I submit my form, my params look like this: "bike" => { "frame" => { "id" => "4" }, "chain" => { "id" => "19" }, ... } In my controller, the following code breaks: @bike = Bike.new(params[:bike]) > Frame(#90986230) expe...