Saturday, April 21, 2012

Re: [Rails] Re: rails query [3.2]

Hi Erwin,

I'm sorry I didn't see your first post.

On Sat, Apr 21, 2012 at 8:12 AM, Erwin <yves_dufour@mac.com> wrote:
<snip>

>> I would like to have a single line to get both, posted and commented
>> counts
<snip>

>> where am I wrong ?  thanks for feedback

Why do you want to count 2 separate / independent resources in one SQL
statement? I'd bet a nickel that it's going to be less efficient from
a processing perspective, and it's certainly less readable than:

users = User.includes(:posts, :comments)
users.each do |u|
puts u.id.to_s + u.posts.size.to_s + u.comments.size.to_s
end

Best regards,
Bill

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