Hi guys,
I’m trying to do something that I imagine is quite common: implementing
a search for a particular record in a table (or ActiveRecord of Model).
In order to display the search results properly, I call count() to count
the number of search results before I do the actual search using find().
And this is where the problem is.
Sometimes I want to search using criteria that are in linked tables, e.g
I might have 2 tables, ‘book’ and ‘author’, and I want to find all the
books by a certain author. This is easy with find(); I can just put the
author table in the :include parameter. On the other hand, for count() I
must provide a fragment of SQL for the ‘joins’ parameter. Obviously
find() does this internally, generating the required SQL code from
:include. It seems to me that this in an inconsitency between the two
functions.
My question is, what is the function that find() calls to do this and
can I call it myself?
Maybe there is an easier way to implement this search functionality
using functions that I don’t know about. But in my opinion, shouldn’t
count() be exactly like find(:all) except it contains ‘SELECT count(*)
FROM’ instead of ‘SELECT * FROM’?
David.