polymorphic-associations

Searching polymorphic associations in Rails

Hello all, I have a need in my app to allow users to bookmark a post. They should only be able to create one bookmark per post. I've set up my polymorphic association like so: class Post < ActiveRecord::Base has_many :bookmarks, :as => :bookmarkable end class Bookmark < ActiveRecord::Base belongs_to :bookmarkable, :polymorphic =...

Should I joint-index an ActiveRecord polymorphic association?

I have a metric table that I expect to be very large. It has a polymorphic association so that it can belongs_to other models that want to record some metric. I typically index association columns like this to speed up association loading. I've heard people talking about joint-indexing this association. This looks like: add_index :c...

Model and controller design approach for polymorphic assocation

Below I have outlined the structure of a polymorphic association. In VacationsController I put some comments inline describing my current issue. However, I wanted to post this to see if my whole approach here is a little off. You can see in business_vacations_controller and staff_vacations_controller that I've had to make 'getters' for ...

Find your way up the polymorphic tree to one parent..

I have a simple polymorphic association #comment.rb belongs_to :commentable, :polymorphic => true has_many :comments, :as => :commentable #post.rb has_many :comments, :as => :commentable accepts_nested_attributes_for :comments, :allow_destroy => true So in IRB I can do, Post.comments, or Commen...

Should I make a different join table for the same type of relationship?

I have posts that can be voted on by a polymorphic association. Now I am making comments votable as well. Can I share the same models and logic for this for my comments? Or do I have to make a new model relationship ? #post.rb has_many :votes, :as => :votable has_many :...