On Mon, Oct 25, 2010 at 9:51 PM, Peter Hickman <
[email protected]> wrote:

> Having a problem getting my head round a named_scope problem
>
> I have the following:
>
> class Event < ActiveRecord::Base
>  has_many :event_alerts
> end
>
> class EventAlert < ActiveRecord::Base
>   belongs_to :event
> end
>
> I want to create a named scope that returns only those events that
> have event alerts.
>
> But I just can't seem to get my head around it. This is Rails 2.3 if
> that is of importance.


Depending on the db you're using, an EXISTS on the :where clause should do
the trick.

-- 
Erol M. Fornoles
http://erolfornoles.posterous.com
http://github.com/Erol
http://twitter.com/erolfornoles
http://ph.linkedin.com/in/erolfornoles

-- 
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