Hi to all,

This is my first post here, I would first like to salute you all and
praise the great work you guys are doing on RoR.

There is a patch (http://dev.rubyonrails.org/ticket/6461) sitting for
quite a while on the Trac for nested has_many :through associations. I
think it is a must and I have seen it requested quite a few times
(http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/
4517fb8bf464921a/6f4c544fb948b9d1  and
http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/1ee28a00febcbc42/b34f05aae9e01688
).

The patch seems to be all sorted out for more than 2 months (all tests
working). It was even made into a plugin by the author. Is there a
reason it was not applied yet? I didn't find anything about it in this
list or elsewhere.

I think it greatly simplifies apps that have complex (=large number)
models. To make a case for it, I will show a simple 'posts and
comments' example where it would be very useful (I am just writing the
essential).

class CommentRating < AR:Base
  belongs_to :comment
  belongs_to :user
end

class Comment < AR::Base
  has_many :comment_ratings
  belongs_to :user
end

class Post < AR::Base
  has_many :comments
  belongs_to :user
end

class User < AR::Base
  has_many :posts
  has_many :comments, :through=>:posts
  has_many :comment_ratings, :through=>:comments
end

If I wanted to allow a user to review only the ratings given to the
comments from his posts, I could use the contextualized finder:
current_user.comment_ratings.find(params[:id])

I know this example seems a little "forced", but as your modelspace
gets larger, without this kind of nesting, you find yourself having to
write more and more custom finders, with joins, scopes, etc, for
things that could be handled in a much simpler way.

Cheers,

Bernardo (from Brazil)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to