Thursday, August 18, 2011

[Rails] Question about query

Hi guys,
I have the following problem:
In my application there is 3 entities that have this relationship:
-1 post has many comments
-1 comment belongs to one user and to one post
-1 comment could be voted by many users
My problem is how can I make a query to search for the best rated
comment, in other words, How can I get the comment from one user which
has the most quantity of good votes?
I don't know how to make this query... ;/

my entities are structure like this:

class Post < ActiveRecord::Base
belongs_to :user
belongs_to :post_type
has_many :post_comments
end

class PostComment < ActiveRecord::Base
belongs_to :user
belongs_to :post
has_many :post_comment_votes
end

class PostCommentVote < ActiveRecord::Base
belongs_to :vote_type
belongs_to :user
belongs_to :post_comment
end

class VoteType < ActiveRecord::Base
has_many :post_comment_votes
end


Thx ;D

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate