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 at 
http://groups.google.com/group/hobousers?hl=en.

Reply via email to