Is it possible to do a find all, and then return the # of items? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
David Zhu wrote:> Is it possible to do a find all, and then return the # of items?Better to use the built-in aggregate functions. http://railsapi.com/doc/rails-v2.3.5/classes/ActiveRecord/Calculations/ClassMethods.html#M001357 This will perform the count in SQL and will be much more efficient than building all those ActiveRecord objects. -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Apr 29, 2010, at 2:01 PM, Robert Walker wrote:> David Zhu wrote: >> Is it possible to do a find all, and then return the # of items? > > Better to use the built-in aggregate functions. > > http://railsapi.com/doc/rails-v2.3.5/classes/ActiveRecord/Calculations/ClassMethods.html#M001357 > > This will perform the count in SQL and will be much more efficient > than > building all those ActiveRecord objects.+1, but if you already have them you can use .size() to get the count. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks guys, If I have nested associations, how could i count that? For ex- I want to do something like @totalcount = Post.comment.count , or something like that How could i do that? ( i want to count the comments that belong to that post) thanks On Apr 29, 5:07 pm, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote:> On Apr 29, 2010, at 2:01 PM, Robert Walker wrote: > > > David Zhu wrote: > >> Is it possible to do a find all, and then return the # of items? > > > Better to use the built-in aggregate functions. > > >http://railsapi.com/doc/rails-v2.3.5/classes/ActiveRecord/Calculation... > > > This will perform the count in SQL and will be much more efficient > > than > > building all those ActiveRecord objects. > > +1, but if you already have them you can use .size() to get the count. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
On Mon, May 10, 2010 at 7:37 PM, David Zhu <dzwestwindsor45-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks guys, > > If I have nested associations, how could i count that? For ex- > > I want to do something like @totalcount = Post.comment.count , or > something like that > > How could i do that? ( i want to count the comments that belong to > that post)Assuming that Post has_many :comments, and you''ve gotten the particular post of interest to be referenced by the variable post. For the sake of the example below, let''s say that the id of that post is 42 then either post.comments.count or post.comments.size will do a sql query like SELECT count(*) AS count_all FROM `users` WHERE (`users`.account_id = 42) and return the value of count_all HTH -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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? 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 whats the syntax for that? DOes that make sense? How could I do something like that? Thanks :) -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org http://gaslightsoftware.com rab-/VpnD74mH8+00s0LW7PaslaTQe2KTcn/@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Oh ok thanks! But just to make sure we are on the same page- Page has many comments Comments has many Davids 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 11 May 2010 13:32, David Zhu <dzwestwindsor45-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Oh ok thanks! > > But just to make sure we are on the same page- > > Page has many comments > Comments has many DavidsI 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
i need a join table? is the join table my comments table? On May 11, 8:36 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 11 May 2010 13:32, David Zhu <dzwestwindso...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
On Tue, May 11, 2010 at 8:43 AM, David Zhu <dzwestwindsor45-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On May 11, 8:36 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:>> 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 > i need a join table? is the join table my comments table?Yes but.. First I notice that you continue to use code of the form Post.comments. .... Which won''t work, since the associations like belongs_to, has_many ... create INSTANCE rather than class methods. You need to use something like some_post.comments. .. where some_post refers to a particular instance of Post. Second, I suspect that David here is a hypothetical model class, and that what you might really be trying to do is count all the comments made by a particular user. Maybe you want something like: class Post < ActiveRecord::Base has_many :comments end class User < ActiveRecord::Base end class Comment < ActiveRecord::Base belongs_to :post belongs_to : user named_scope :by_user, lambda {|user| :conditions => {:user => user} end then some_post = Post.find(params[:id]) # or some other code to get a particular post david = User.find_by_userid("david") # or some other code to get a particular user some_post.comments.by_user(david).count -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 11 May 2010 13:43, David Zhu <dzwestwindsor45-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> On 11 May 2010 13:32, David Zhu <dzwestwindso...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org. >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
On May 11, 9:32 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 11 May 2010 13:43, David Zhu <dzwestwindso...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> On 11 May 2010 13:32, David Zhu <dzwestwindso...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-talk@googlegroups.com. > >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> > 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org. > >> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.Ok Colin, about not top posting, is this top posting? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
[long post intentionally not snipped so the comments at the end make sense] On 11 May 2010 21:11, David Zhu <dzwestwindsor45-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On May 11, 9:32 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> On 11 May 2010 13:43, David Zhu <dzwestwindso...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> >> On 11 May 2010 13:32, David Zhu <dzwestwindso...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-talk@googlegroups.com. >> >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> >> > 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-talk-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. >> >> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> >> 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org. >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > > Ok Colin, > > about not top posting, is this top posting?No, it is bottom posting, which in this case is not much better. This can be seen from the fact that you had to preface your text with "about top posting", and that it is preceded by a large amount of irrelevant text. Had your reply read as follows it would be even clearer: On May 11, 9:32 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 11 May 2010 13:43, David Zhu <dzwestwindso...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > [snip] > > 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.Ok Colin, Is this top posting? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
On 11 May 2010 21:11, David Zhu <dzwestwindsor45-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> about not top posting, is this top posting?No. But it wasn''t at the appropriate place in text. Making people scroll through pages of footers to get to your question won''t incline them to answer you in future... just a thought. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.