sti

Single-table-inheritance or two tables?

Hi, Suppose I have a table with the following columns (a list of words): word: varchar contributor: integer (FK) Now, suppose I wanted to have translations for each "word". What would be best? Having a second table? word: integer (FK) translation: varchar contributor: integer (FK) lang: integer (FK) Or all in the same table? word...

ActiveRecord Inheritance with Different Database Tables

I have just started investigating using more advanced models in Rails. One that I use regularly, with great success, is model where a many-to-many cross-reference relationship is accessed by a class that itself is a sub-class of the base class in the many-to-many relationship. This way the cross-reference class can act as a stand-in for...

Problem caching Model instances on a constant in Rails

I am using Single-Table Inheritance (STI) on one of my models for a Rails App and I am having problems storing model objects on a constant. I have isolated the problem into a sample project and submitted it to GitHub: http://github.com/fcoury/rails-sti-caching What I am trying to do is loading a model instance (in this case a Music mode...

Is this a legitimate use of Rails' Single Table Inheritance?

I've just been reading Chad Fowler's blog post about 20 Rails Development No-Nos. On Single Table Inheritance he comments: The storage of a column called “type” which holds a class name is a pretty good indicator that something fishy is going on. It’s fishy but not always bad. I think, though, that any time you use it you should ask ...

HABTM association associated to single table inheritance help!

hi all I have a product model that has many sections and a section can belong to many products. The section model has subclasses as features, standardAccessories and OptionalAccessories in a STI. Each having field title, body, image url and (optionalAccessories) has price. my models are class Product < ActiveRecord::Base has_and...

Rails STI Style Inheritence for multiple roles per user

I've been reading up on a bit of STI Inheritence examples for Rails, While it looks like it would suit my needs (User role/types inheriting from a base class of user). It seems like it doesn't handle a user having multiple roles too well. Particularly because it relies on a type field in the database. Is there a quick and easy work arou...

SearchLogic + STI

Trying to implement a search logic search that uses associations with STI but I’m having a problem where it is not select the STI records as the subclass but the parent. Example: class Users end class Artist < User has many :agents, :through => :agents artists end class Agent < User has many :artists, :through => :agents artists...

A polymorphic object that belongs to a quasi-STI object: object_type is incorrect

Consider: class Person < ActiveRecord::Base class << self def setup has_one :address, :as => :addressable end end end class Employee < Person setup end class Address < ActiveRecord::Base belongs_to :addressable, :polymorphic => true end # Shouldn't this be 'Employee'? Is it possible to override? Employee.create....

STI and form_for problem

I am using Single Table Inheritance for managing different types of projects. Models: class Project < ActiveRecord::Base end class SiteDesign < Project end class TechDesign < Project end Edit action from projects_controller: def edit @project = Project.find(params[:id]) end View edit.html.erb: <% form_for(@project, :url => {...

Rails Single table inheritance problem

I'm trying to setup single table inheritance in my Rails app for a User model and its subclasses Member, Subscriber, and Staff. I have a model file for each: user.rb, member.rb, etc The user model is defined: class User < ActiveRecord::Base; end; I subclassed the other models as such: class Member < User; end; and so on. In my users t...

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 reputation represents (User, Post, Response) If there were C++, I would have a superclass ...

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 < ActiveRecord::Base belongs_to :user end class FreeAdvertisement < Advertisement end class Paid...

Can this STI structure be achived in Rails?

I want to have these models: AbstractArticle Article < AbstractArticle FeaturedArticle < AbstractArticle I want the name of the database table to be articles and not abstract_articles. (As the convention suggests) Is this possible with Rails? How can I tell my base model to use a different table? Will STI still work even though the ...

ActiveRecord::Base#find returns no records in Single Table Inheritance (STI)

app/models class Amodel < ActiveRecord::Base end class Bmodel < Amodel end class Cmodel < Bmodel end db/migrate create_table :amodels do |t| t.string :type end on script/console... $ script/console Loading development environment (Rails 2.3.4) >> Cmodel.create => #<Cmodel id: 1, type: "Cmodel"> >> Bmodel.find(:all) => [#<...

Rails STI: invoking child method

Hi, I've got something like this class Reply < AR::Base end class VideoReply < Reply def hello p 'not ok' end end class PostReply < Reply def hello p 'ok' end end ... So when I am creating object: # params[:reply][:type] = "VideoReply" @reply = Reply.new(params[:reply]) How can I invoke child method (in this case...

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...

Rails, Am I wrong to think Polymorphic Associations are overrated, limiting, and unnecessary?

OK, so I've been toying with different ways of organizing my Rails 3 apps regarding STI and Polymorphic Associations. I was trying to find a way that is both easy to code, and easy to use, and has the highest chance of being the most compatible with any future changes. After alot of reading a lot of optionated (and often lacking and po...

ActiveRecord STI delete doesn't work correctly

I want to store two models using active record, but delete doesn't work as expected. Evaluation has id, name and description and SqlEvaluation has additional two columns of query_string and database. I want to use those two tables, and eval_typ_id is used to distinguish which subclass should be used: 1 for SqlEvaluation. create tabl...