The counter_cache is GREAT, however i don't think i can use it in my particular case. I have 3 different states of event attendees, and i need the sum of only 2 of them to compare against the database, and the counter_cache gives the full count.
But it will definitely be used again somewhere else in my future development.. THANKS ALOT..! On 5 Maj, 19:29, kevinpfromnm <[email protected]> wrote: > Ahh.. leave it to Matt to point out the simple and obvious solution. > > On May 5, 7:55 am, Matt Jones <[email protected]> wrote: > > > > > On Wed, May 5, 2010 at 8:37 AM, Mikkel WF <[email protected]> wrote: > > > I searched around on the net and managed to piece this scope together: > > > > named_scope :missing, { > > > :joins => "INNER JOIN event_attendees ON event_attendees.event_id > > > = events.id", > > > :select => "events.*, count(event_attendees.id) as c", > > > :group => "event_attendees.event_id", > > > :having => "c < events.attendees_needed AND event_attendees.state ! > > > = 'available'" > > > > } > > > > It seems to work like a charm.. My SQL is a bit rusty though, so it > > > might not be the most appropriate SQL statement.. I've tried to use a > > > RIGHT JOIN, but it wasn't implemented into sqlite it seems.. > > > > But the scope is not intented for a site with that meny users, so i'm > > > not going to work more with it.. > > > The other way to do this would be to counter_cache the event_attendees > > association, then just compare that number (which will be a column in > > the events table) with the required number. > > > --Matt Jones > > > -- > > You received this message because you are subscribed to the Google Groups > > "Hobo Users" 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 > > athttp://groups.google.com/group/hobousers?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Hobo Users" 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 > athttp://groups.google.com/group/hobousers?hl=en. -- You received this message because you are subscribed to the Google Groups "Hobo Users" 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/hobousers?hl=en.
