@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.)
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...@gmail.com> wrote:
> What are the results of this?
>
> @expense = Expense.find(:all, :conditions => "clientid = 'tbg'")
>
> - Adam
>
Mike
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/.
On Jul 12, 3:21 pm, "Mike Garey" <random...@gmail.com> wrote:
> have you checked the sql that it's generating and tried to enter that
> manually into your sql client?
>
> 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...@gmail.com> wrote:
> have you checked the sql that it's generating and tried to enter that
> manually into your sql client?
>
> Mike
>
On Jul 12, 3:27 pm, Matthew Rudy <rails-mailing-l...@andreas-s.net>
wrote:
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...@andreas-s.net>
wrote:
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
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...@gmail.com> wrote:
You should take a look at the following post for more information:
you can find the will_paginate plugin here: http://errtheblog.com/post/4791
Mike
On 7/12/07, TomB <tba...@gmail.com> wrote:
>
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...@gmail.com> 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
>