Rails polymorphic associations, two assoc types in one class

Posted by snitko on Stack Overflow See other posts from Stack Overflow or by snitko
Published on 2009-12-29T19:45:13Z Indexed on 2010/04/22 8:03 UTC
Read the original article Hit count: 396

Consider a class:

class Link < ActiveRecord::Base

  has_many :link_votes, :as => :vote_subject, :class_name => 'Vote'
  has_many :spam_votes, :as => :vote_subject, :class_name => 'Vote'

end

The problem is, when I'm adding a new vote with @link.link_votes << Vote.new the vote_subject_type is 'Link', while I wish it could be 'link_votes' or something like that. Is this an AR limitation or is there a way to workaround this thing?

I've actually found one related answer, but I'm not quite sure about what it says: http://stackoverflow.com/questions/1168047/polymorphic-association-with-multiple-associations-on-the-same-model/1764117#1764117

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about polymorphic-associations