I havent played with polymorphic associations yet, but is there some reason this wont work?<br>
<br>
class Comment <ActiveRecord::Base<br>
belongs_to :commentable, :polymorphic => true<br>
belongs_to :user<br>
end<br>
<br>
>That's the problem with rails' strict naming conventions... if you<br>
>want to create more than one link between the same two tables, you're<br>
>a bit stuck. Hope this helps.<br>
<br>
That's a common misconception. The naming is just a convention (or, an easy default)-- it can always be configured differently.<br>
<br>
class Comment <ActiveRecord::Base<br>
belongs_to :commentable, :polymorphic => true<br>
belongs_to :author, :class_name => "User", :foreign_key => "user_id"<br>
end<br>
<br>
Would work the same as the above.<br>
<br>
Maurice<br><br><div><span class="gmail_quote">On 3/31/06, <b class="gmail_sendername"><a href="mailto:njmacinnes@gmail.com">njmacinnes@gmail.com</a></b> <<a href="mailto:njmacinnes@gmail.com">njmacinnes@gmail.com</a>> wrote:
</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Maybe if you have an intermediate table, which links one-to-one to the<br>users (maybe called "commentor"), then each comment can link to that?
<br>It's a little clunky, but less so than any alternative I can think so.<br>That's the problem with rails' strict naming conventions... if you<br>
want to create more than one link between the same two tables, you're<br>
a bit stuck. Hope this helps.<br>
-Nathan<br><br>On 31/03/06, Eric Schultz <<a href="mailto:hammy@charter.net">hammy@charter.net</a>> wrote:<br>> I'm playing around with RoR and I'm having trouble figuring out how to<br>> describe a certain relationship. I'm building a social networking site
<br>> where you have users who can comment on other users, photos, videos, and<br>> blogs. I've figured out how to have a comment belong to a user or media<br>> item through a polymorphic relationships but I dont' know how to have
<br>> the comment also be "owned" by the user who made the comment. I've<br>> included some code to help with the description:<br>><br>> #User class<br>> class User < ActiveRecord::Base<br>> has_many :photos
<br>> has_many :blogs<br>> ...<br>> end<br>><br>> #photo (also blog and video are similar)<br>> class Photo < ActiveRecord::Base<br>> belongs_to :user<br>> has_many :comments, :as => :commentable
<br>> end<br>><br>> #comment class<br>> class Comment < ActiveRecord::Base<br>> belongs_to :commentable, :polymorphic => true<br>> end<br>><br>> #comment table includes the following fields:<br>
><br>> id<br>> content <--- the actual comment text<br>> user_id <--- the user who made the comment<br>> commentable_id<br>> commentable_type<br>><br>><br>> I've thought this over for 2 days and I still can't seem to figure out a
<br>> way to describe what I want to describe... Does anyone have any ideas or<br>> suggestions on how to do this?<br>><br>> --<br>> Posted via <a href="http://www.ruby-forum.com/">http://www.ruby-forum.com/
</a>.<br>> _______________________________________________<br>> Rails mailing list<br>> <a href="mailto:Rails@lists.rubyonrails.org">Rails@lists.rubyonrails.org</a><br>> <a href="http://lists.rubyonrails.org/mailman/listinfo/rails">
http://lists.rubyonrails.org/mailman/listinfo/rails</a><br>><br>_______________________________________________<br>Rails mailing list<br><a href="mailto:Rails@lists.rubyonrails.org">Rails@lists.rubyonrails.org</a><br><a href="http://lists.rubyonrails.org/mailman/listinfo/rails">
http://lists.rubyonrails.org/mailman/listinfo/rails</a><br></blockquote></div><br>