I''m learning Rails. I have a simple find that doesn''t work: @expense = Expense.find_all_by_clientid(''tbg'') There a number of records in the MySQL DB with clientid = ''tbg'' but the find returns all records, including those with other values for clientid. I''ve tried at least a half-dozen versions of find, including find (by itself),and find_by_sql with appropriate parameters as given in Rails docs online and Agile Web Development with Rails (p212++). No matter how I try this retrieval on the Web, it always returns all records in the DB. When I did the same find in the terminal, it worked, only returning the records where clientid ''tbg'' Is t here a reason for this? What am I missing? (I''m running on MacOSX-10.4.9, on a PB-G4, 1.5GHz, using Standard Rails Mar 2007 running under Locomotive 2.0.8.) --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
What are the results of this? @expense = Expense.find(:all, :conditions => "clientid = ''tbg''") - Adam On 6/29/07, TomB <tbajzek-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > I''m learning Rails. I have a simple find that doesn''t work: > > @expense = Expense.find_all_by_clientid(''tbg'') > > There a number of records in the MySQL DB with clientid = ''tbg'' but > the find returns all records, including those with other values for > clientid. I''ve tried at least a half-dozen versions of find, > including find (by itself),and find_by_sql with appropriate > parameters as given in Rails docs online and Agile Web Development > with Rails (p212++). No matter how I try this retrieval on the Web, > it always returns all records in the DB. When I did the same find in > the terminal, it worked, only returning the records where clientid > ''tbg'' > > Is t here a reason for this? What am I missing? > > (I''m running on MacOSX-10.4.9, on a PB-G4, 1.5GHz, using Standard > Rails Mar 2007 running under Locomotive 2.0.8.) > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Adam, The results are exactly the same as in the case I submitted- all records are retrieved. Tom On Jun 30, 7:26 am, "Adam Parrott" <pingusk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> What are the results of this? > > @expense = Expense.find(:all, :conditions => "clientid = ''tbg''") > > - Adam > > On 6/29/07, TomB <tbaj...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I''m learning Rails. I have a simple find that doesn''t work: > > > @expense = Expense.find_all_by_clientid(''tbg'') > > > There a number of records in the MySQL DB with clientid = ''tbg'' but > > the find returns all records, including those with other values for > > clientid. I''ve tried at least a half-dozen versions of find, > > including find (by itself),and find_by_sql with appropriate > > parameters as given in Rails docs online and Agile Web Development > > with Rails (p212++). No matter how I try this retrieval on the Web, > > it always returns all records in the DB. When I did the same find in > > the terminal, it worked, only returning the records where clientid > > ''tbg'' > > > Is t here a reason for this? What am I missing? > > > (I''m running on MacOSX-10.4.9, on a PB-G4, 1.5GHz, using Standard > > Rails Mar 2007 running under Locomotive 2.0.8.)--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
have you checked the sql that it''s generating and tried to enter that manually into your sql client? Mike On 7/12/07, TomB <tbajzek-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Adam, > > The results are exactly the same as in the case I submitted- all > records are retrieved. > > Tom > > On Jun 30, 7:26 am, "Adam Parrott" <pingusk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > What are the results of this? > > > > @expense = Expense.find(:all, :conditions => "clientid = ''tbg''") > > > > - Adam > > > > On 6/29/07, TomB <tbaj...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > I''m learning Rails. I have a simple find that doesn''t work: > > > > > @expense = Expense.find_all_by_clientid(''tbg'') > > > > > There a number of records in the MySQL DB with clientid = ''tbg'' but > > > the find returns all records, including those with other values for > > > clientid. I''ve tried at least a half-dozen versions of find, > > > including find (by itself),and find_by_sql with appropriate > > > parameters as given in Rails docs online and Agile Web Development > > > with Rails (p212++). No matter how I try this retrieval on the Web, > > > it always returns all records in the DB. When I did the same find in > > > the terminal, it worked, only returning the records where clientid > > > ''tbg'' > > > > > Is t here a reason for this? What am I missing? > > > > > (I''m running on MacOSX-10.4.9, on a PB-G4, 1.5GHz, using Standard > > > Rails Mar 2007 running under Locomotive 2.0.8.) > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
yeah, I suggest you tail log/development.log and see what query is going in there. How about printing out the results of this from the console; "Expense.find_all_by_clientid(''tbg'').map(&:clientid)" clearly the query at least thinks its right. Mike Garey wrote:> have you checked the sql that it''s generating and tried to enter that > manually into your sql client? > > Mike-- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mike, On Jul 12, 3:21 pm, "Mike Garey" <random...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> have you checked the sql that it''s generating and tried to enter that > manually into your sql client? > > Mike > > On 7/12/07, TomB <tbaj...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Adam, > > > The results are exactly the same as in the case I submitted- all > > records are retrieved. > > > Tom > > > On Jun 30, 7:26 am, "Adam Parrott" <pingusk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > What are the results of this? > > > > @expense = Expense.find(:all, :conditions => "clientid = ''tbg''") > > > > - Adam > > > > On 6/29/07, TomB <tbaj...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I''m learning Rails. I have a simple find that doesn''t work: > > > > > @expense = Expense.find_all_by_clientid(''tbg'') > > > > > There a number of records in the MySQL DB with clientid = ''tbg'' but > > > > the find returns all records, including those with other values for > > > > clientid. I''ve tried at least a half-dozen versions of find, > > > > including find (by itself),and find_by_sql with appropriate > > > > parameters as given in Rails docs online and Agile Web Development > > > > with Rails (p212++). No matter how I try this retrieval on the Web, > > > > it always returns all records in the DB. When I did the same find in > > > > the terminal, it worked, only returning the records where clientid > > > > ''tbg'' > > > > > Is t here a reason for this? What am I missing? > > > > > (I''m running on MacOSX-10.4.9, on a PB-G4, 1.5GHz, using Standard > > > > Rails Mar 2007 running under Locomotive 2.0.8.)--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mike, It does 3 queries: SELECT * FROM expenses WHERE (clientid = ''tbg'') SELECT COUNT(*) FROM expenses SELECT * FROM expenses LIMIT 0, 10 The first one works correctly in CocoaSQL, as I''d expect The second one is presumably to find out whether it needs to pageinate the results The third on retrieves all records, and all records are displayed (there happen to be 9 of them) I notice there is no WHERE clause in this query, which looks like a problem to me It later does another query: SHOW FIELDS FROM expenses, which works. Tom On Jul 12, 3:21 pm, "Mike Garey" <random...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> have you checked the sql that it''s generating and tried to enter that > manually into your sql client? > > Mike > > On 7/12/07, TomB <tbaj...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Adam, > > > The results are exactly the same as in the case I submitted- all > > records are retrieved. > > > Tom > > > On Jun 30, 7:26 am, "Adam Parrott" <pingusk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > What are the results of this? > > > > @expense = Expense.find(:all, :conditions => "clientid = ''tbg''") > > > > - Adam > > > > On 6/29/07, TomB <tbaj...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I''m learning Rails. I have a simple find that doesn''t work: > > > > > @expense = Expense.find_all_by_clientid(''tbg'') > > > > > There a number of records in the MySQL DB with clientid = ''tbg'' but > > > > the find returns all records, including those with other values for > > > > clientid. I''ve tried at least a half-dozen versions of find, > > > > including find (by itself),and find_by_sql with appropriate > > > > parameters as given in Rails docs online and Agile Web Development > > > > with Rails (p212++). No matter how I try this retrieval on the Web, > > > > it always returns all records in the DB. When I did the same find in > > > > the terminal, it worked, only returning the records where clientid > > > > ''tbg'' > > > > > Is t here a reason for this? What am I missing? > > > > > (I''m running on MacOSX-10.4.9, on a PB-G4, 1.5GHz, using Standard > > > > Rails Mar 2007 running under Locomotive 2.0.8.)--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Matthew, On Jul 12, 3:27 pm, Matthew Rudy <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> yeah, > I suggest you tail log/development.log > and see what query is going in there. > > How about printing out the results of this from the console; > "Expense.find_all_by_clientid(''tbg'').map(&:clientid)" > > clearly the query at least thinks its right. > > Mike Garey wrote: > > have you checked the sql that it''s generating and tried to enter that > > manually into your sql client? > > > Mike > > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Matthey, The result is from the console is:>> Expense.find_all_by_clientid(''tbg'').map(&:clientid)=> ["tbg", "tbg", "tbg", "tbg", "tbg"] This suggests to me that it has found 5 records, which is the correct number that match. Tom On Jul 12, 3:27 pm, Matthew Rudy <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> yeah, > I suggest you tail log/development.log > and see what query is going in there. > > How about printing out the results of this from the console; > "Expense.find_all_by_clientid(''tbg'').map(&:clientid)" > > clearly the query at least thinks its right. > > Mike Garey wrote: > > have you checked the sql that it''s generating and tried to enter that > > manually into your sql client? > > > Mike > > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 7/12/07, TomB <tbajzek-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Mike, > > It does 3 queries: > > SELECT * FROM expenses WHERE (clientid = ''tbg'') > SELECT COUNT(*) FROM expenses > SELECT * FROM expenses LIMIT 0, 10 > > The first one works correctly in CocoaSQL, as I''d expect > The second one is presumably to find out whether it needs to pageinate > the results > The third on retrieves all records, and all records are displayed > (there happen to be 9 of them)Why is there a limit clause? I see no limit parameter to your original find. Are you paginating the results after your find? It looks like you''re doing the following: @expense = Expense.find_all_by_clientid(''tbg'') @expenses_pages, @expenses = paginate :expenses, :per_page => 10 Are you? Mike --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mike, Yes, the most recent code being: @expense = Expense.find(:all, :conditions => "clientid = ''tbg''") @expense_pages, @expenses = paginate :expenses, :per_page => 10 Tom On Jul 12, 4:04 pm, "Mike Garey" <random...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 7/12/07, TomB <tbaj...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Mike, > > > It does 3 queries: > > > SELECT * FROM expenses WHERE (clientid = ''tbg'') > > SELECT COUNT(*) FROM expenses > > SELECT * FROM expenses LIMIT 0, 10 > > > The first one works correctly in CocoaSQL, as I''d expect > > The second one is presumably to find out whether it needs to pageinate > > the results > > The third on retrieves all records, and all records are displayed > > (there happen to be 9 of them) > > Why is there a limit clause? I see no limit parameter to your > original find. Are you paginating the results after your find? It > looks like you''re doing the following: > > @expense = Expense.find_all_by_clientid(''tbg'') > > @expenses_pages, @expenses = paginate :expenses, > :per_page => 10 > > Are you? > > Mike--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
you''ve got two different arrays there. The @expense array contains the list of filtered expenses, containing only those expense records whose clientid is tbg. The second array, @expenses, contains _all_ expenses, with no conditions applied, other than a limit of 10 per page. You need to add your conditions to your paginate method call. You should take a look at the following post for more information: http://tinyurl.com/35m7e7 you can find the will_paginate plugin here: http://errtheblog.com/post/4791 Mike On 7/12/07, TomB <tbajzek-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Mike, > > Yes, the most recent code being: > > @expense = Expense.find(:all, :conditions => "clientid = ''tbg''") > @expense_pages, @expenses = paginate :expenses, :per_page => 10 > > Tom > > On Jul 12, 4:04 pm, "Mike Garey" <random...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > On 7/12/07, TomB <tbaj...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > Mike, > > > > > It does 3 queries: > > > > > SELECT * FROM expenses WHERE (clientid = ''tbg'') > > > SELECT COUNT(*) FROM expenses > > > SELECT * FROM expenses LIMIT 0, 10 > > > > > The first one works correctly in CocoaSQL, as I''d expect > > > The second one is presumably to find out whether it needs to pageinate > > > the results > > > The third on retrieves all records, and all records are displayed > > > (there happen to be 9 of them) > > > > Why is there a limit clause? I see no limit parameter to your > > original find. Are you paginating the results after your find? It > > looks like you''re doing the following: > > > > @expense = Expense.find_all_by_clientid(''tbg'') > > > > @expenses_pages, @expenses = paginate :expenses, > > :per_page => 10 > > > > Are you? > > > > Mike > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mike, This worked, which seems perfectly reasonable now that I''ve seen it. I''d just not recognized the need to do it this way before your pointed it out. Thanks much, Tom On Jul 12, 5:15 pm, "Mike Garey" <random...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> you''ve got two different arrays there. The @expense array contains > the list of filtered expenses, containing only those expense records > whose clientid is tbg. The second array, @expenses, contains _all_ > expenses, with no conditions applied, other than a limit of 10 per > page. You need to add your conditions to your paginate method call. > > You should take a look at the following post for more information: > > http://tinyurl.com/35m7e7 > > you can find the will_paginate plugin here:http://errtheblog.com/post/4791 > > Mike > > On 7/12/07, TomB <tbaj...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Mike, > > > Yes, the most recent code being: > > > @expense = Expense.find(:all, :conditions => "clientid = ''tbg''") > > @expense_pages, @expenses = paginate :expenses, :per_page => 10 > > > Tom > > > On Jul 12, 4:04 pm, "Mike Garey" <random...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On 7/12/07, TomB <tbaj...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Mike, > > > > > It does 3 queries: > > > > > SELECT * FROM expenses WHERE (clientid = ''tbg'') > > > > SELECT COUNT(*) FROM expenses > > > > SELECT * FROM expenses LIMIT 0, 10 > > > > > The first one works correctly in CocoaSQL, as I''d expect > > > > The second one is presumably to find out whether it needs to pageinate > > > > the results > > > > The third on retrieves all records, and all records are displayed > > > > (there happen to be 9 of them) > > > > Why is there a limit clause? I see no limit parameter to your > > > original find. Are you paginating the results after your find? It > > > looks like you''re doing the following: > > > > @expense = Expense.find_all_by_clientid(''tbg'') > > > > @expenses_pages, @expenses = paginate :expenses, > > > :per_page => 10 > > > > Are you? > > > > Mike--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---