While I agree that any additional trips to the database or additional joins
to a query are more costly than not doing them, and I would love to see some
benchmarking here and get any performance gains possible, I'm not sure I
agree with you implication that this is a reason for exclusion.

As I understand it, the purpose of the plugin is not to increase
performance, but rather to make it easier and cleaner to do things we are
already doing.

>From Bernardo's example:

> 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
>

With out the plugin one would have to do something like:


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

  def comments_rating #or use find_by_sql
    ratings = []
    comments.each{ |c| ratings << c.comment_ratings}
    ratings.flatten
  end
end


And that is just to get a finder. One would have reimplement every hm method
that they need to use.

So I think the performance would be similar to the methods already being
used, but much much cleaner.


My use case is Business -> BusinessOwner -> User -> Contacts (where
BusinessOwner is a special kind of BusinessMember) (I do have a good
business rule reason why the contact is owned by the business owner and not
the business).

Here is the code:
 Business.find(5).contacts

Here is the query produced by the plugin:
 SELECT contacts.* FROM contacts INNER JOIN users ON (contacts.owner_id =
users.id) INNER JOIN business_members ON (users.id =
business_members.user_id) WHERE (business_members.business_id = 5 AND type =
'BusinessOwner')

Which I think is a much better query than the comment_ratings I wrote above
would use.


Thanks,
steven a bristol

--~--~---------~--~----~------------~-------~--~----~
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