On 11 May 2010 13:43, David Zhu <dzwestwindso...@gmail.com> wrote: > i need a join table? is the join table my comments table?
It already is a join table, you just need to tell rails that it can use it as such. By the way could you not top post (so insert your comments at the appropriate point in the email you are replying to instead, as I have done here)? It makes it easier to follow the thread. For example your mail just says "I need a join table? .." but it is not at all clear what this is in reply to. Thanks Colin > > On May 11, 8:36 am, Colin Law <clan...@googlemail.com> wrote: >> On 11 May 2010 13:32, David Zhu <dzwestwindso...@gmail.com> wrote: >> >> > Oh ok thanks! >> >> > But just to make sure we are on the same page- >> >> > Page has many comments >> > Comments has many Davids >> >> I believe that if you also say Page has_many davids through comments >> then you can get at all the davids for a post by >> @post.davids >> and hence you can use @posts.davids.count >> >> Colin >> >> >> >> >> >> >> >> > Would >> >> > @davidcount = Post.comments.map {|comment| comment.davids.count}.sum >> >> > find out how many David's are in a certain Post? >> >> > Just to clarify, im not trying to find All of the David's that exsit >> > in the entire database, just the amount of Davids that belongs to the >> > post. But the part i dont understand is how to count up the David's >> > that belongs to that Post, because there are comments in between. >> > (post has many comments, comments has many davids) And i want to find >> > out for a certain post (@post) how many davds belongs to it) >> >> > So would @davidcount = Post.comments.map {|comment| >> > comment.davids.count}.sum work for something like that? >> >> > Thank you >> >> > -- >> > 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-t...@googlegroups.com. >> > To unsubscribe from this group, send email to >> > rubyonrails-talk+unsubscr...@googlegroups.com. >> > For more options, visit this group >> > athttp://groups.google.com/group/rubyonrails-talk?hl=en. >> >> -- >> 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-t...@googlegroups.com. >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscr...@googlegroups.com. >> For more options, visit this group >> athttp://groups.google.com/group/rubyonrails-talk?hl=en.- Hide quoted text - >> >> - Show quoted text - > > -- > 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-t...@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- 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-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.