Hi, :client has_many :numbers. "numbers" table has a lot of columns
I'm not interested in. And some clients has *a lot* of numbers.
The problem:
When I display the ClientsController action "list", AS loads all the
associated numbers (with all their columns) for the displayed clients
(20-40), but finally, the column "Numbers" just shows the total number
of "numbers". Loading so many "numers" entries is a very expensive
operation and takes long time, too much, which makes the whole
application very slow.
However I've realized that client.numbers.size is a fast operation. So
what I would like is:
1) When displaying "clients" list, for each client just its total
number of "numbers" to be computed, no more.
2) When I click in a "Numbers" column then I would see the typical
nested view of "client" associated "numbers". If it's possible, just
some specific columns of "numbers" table should be loaded (those that
the NumbersControllers shows in the "list" action").
In this way I would get *exactly* the same result as the current one,
but in a much more efficient way.
The question:
Is it possible? I've got something "similar" by creating a virtual
column "num_numbers" in Client model:
def num_numbers
self.numbers.size
end
And then, in ClientsHelpers I've created a field override to show a
link to Numbers list by filtering numbers belonging to the client:
def client_num_numbers_column(client)
link_to client.num_numbers, :action => :list, :controller => :numbers
end
However this is a not very good solution because:
- I compute twice client.numbers.size (first time whe AS loads the
data, and second time when AS applies the field override). I could
store client.numbers.size in a Client attribute but it seems a bit
ugly.
- I don't get a nested view, but a link to other page, which is not so cool.
So more than asking how to achieve it, I'd prefer to suggest that the
beaviour I propose above could be a good and useful feature for AS
itself (why to load all the columns of a table just to show the total
number of entries?).
Thanks a lot.
--
Iñaki Baz Castillo
<[email protected]>
--
You received this message because you are subscribed to the Google Groups
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/activescaffold?hl=en.