On Sep 16, 10:51 pm, surge <[EMAIL PROTECTED]> wrote:
> By "view" you mean an SQL view? Or did you mean something else? Also,
> what kind of include did you have in mind?

Yeah, I meant SQL view. MySQL views seem to play nicely with Rails so
you should have no problems using that approach. If you create a
"tickets_with_counts" view with a COUNT subquery in it, you save the
db and AR from having to fetch all the corresponding records from
issues and composing them into AR objects.

I was meaning to say "select" instead of "include". Assuming that your
association is a has_many, adding:

:select => "<fields you need>, COUNT(SELECT issues.id FROM issues
WHERE issues.ticket_id = tickets.id) AS issue_count"

in your Ticket.find call will give you an additional read-only field
called issue_count which does not rely on fetching and composing issue
records.
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to