Forum: Ruby on Rails Keeping separate lists of parent objects

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Steve H (Guest)
on 2009-01-27 13:02
(Received via mailing list)
OK here's the deal.  I have a Verification object that I want to use
to allow users to verify data (Posts, Pics, Addresses, etc).  Each
Post, Address, etc object will be related 1:1 to a Verification

But I want to have the Verification keep 3 separate lists of users.  I
have generated the following migration code, but i don't think it's
going to work properly:
  def self.up
    create_table :verifications do |t|
      t.references :voted_real
      t.references :voted_fake
      t.references :flagged


See I want voted_real to be a list of users who have voted "Real",
similarly :voted_fake should be a list of users who have voted "Fake"
and flagged to be a list of users who have "flagged" content (as
offensive, inappropriate, etc).

So you see, the standard options for ActiveRecord Associations will
not suffice (as far as I can tell).

Can someone help me out here?  I maybe just need a different design or
maybe I can use polymorphic associations, but I'm not sure yet.  I
think I can use polymorphic associations to associate the
Verifications to the other objects, but not to accomplish what I want
to do with the Verification to User relationship(s).

I appreciate your help!!

Steve H (Guest)
on 2009-01-27 21:08
(Received via mailing list)
I think I've figured it out.  Sorry for posting what amounts to an
architectural question here, I'm guessing that's not really what this
board is for.

For anyone curious about what I decided to do:

I haven't totally decided yet.  I might trash the idea of a
"Verification" class, and instead opt for a Vote class:

Then it would be a polymorphic association like this:
class Vote < ActiveRecord::Base
  belongs_to :voteable, :polymorphic => true

class Post < ActiveRecord::Base
  has_many :votes, :as => :voteable

class Product < ActiveRecord::Base
  has_many :votes, :as => :voteable


Otherwise if I stick with my verification class, I think I'll need to
do some sort of HMABT relationship, and I honestly don't see the
point.  So yeah.  I'll probably just do the Vote thing.

This topic is locked and can not be replied to.