On May 11, 2010, at 7:47 AM, David Zhu wrote:

Thank you,

I swear this is the last question about this-

Is there a way to go one level deeper, so instead of @totalcount =
Post.comments.count, could I have lets say... ---

@totalcount = Post.comments.davids.count, if comments has many davids?

a Comment might have many davids, but you have comments.


So basically instead of just post has many comments, i also want to
add comments has many davids, and then find out how many davids are in
the Post.

so for each comment, you want the davids, and count up the total


So whats the syntax for that?

DOes that make sense? How could I do something like that? Thanks :)


@davidcount = Post.comments.map {|comment| comment.davids.count}.sum

But it might be more efficient to say something like:

@davidcount = David.count

depending on what you really want to know.

-Rob

Rob Biedenharn
http://agileconsultingllc.com
        [email protected]
http://gaslightsoftware.com
        [email protected]




--
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 [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-talk?hl=en.

Reply via email to