Hi everyone,

I'm sure the answer is out there and quite simple, but I haven't been
able to find it.

Suppose I have the following classes with polymorphic associations:

class Comment < ActiveRecord::Base
  belongs_to :commentable, :polymorphic => true
end

class Camera < ActiveRecord::Base
  has_many :comments, :as => :commentable
end

class Computer < ActiveRecord::Base
  has_many :comments, :as => :commentable
end

class Book < ActiveRecord::Base
  has_many :comments, :as => :commentable
end

How do I also make the Comment class belong_to a User class? Would the
User class be parallel to the Camera, Computer, and Book classes? For
example, would I define the relationship between User and Comment as
such:

class User < ActiveRecord::Base
  has_many :comments, :as => :commentable
end

And how would I go about referencing the comments through the User-
>Camera/Computer/Book association? Would it be as such?

@user.computers.comments.empty? # For example

Thanks in advance!

Mike


-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to