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. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mon, Oct 25, 2010 at 9:51 PM, Peter Hickman < peterhickman386-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
instead of named scopes use class methods http://www.railway.at/2010/03/09/named-scopes-are-dead/ -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Radhames Brito wrote in post #956904:> instead of named scopes use class methods > > http://www.railway.at/2010/03/09/named-scopes-are-dead/That article applies only to Rails 3. The OP said he was using Rails 2.3. Therefore, your advice is irrelevant. Please read all details before giving advice. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mon, Oct 25, 2010 at 11:52 AM, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> Radhames Brito wrote in post #956904: > > instead of named scopes use class methods > > > > http://www.railway.at/2010/03/09/named-scopes-are-dead/ > > That article applies only to Rails 3. The OP said he was using Rails > 2.3. Therefore, your advice is irrelevant. > >not irrelevant as he can use class methods anyway and is are more flexible, i posted the link with general info on scopes as you can see the author praises scopes in rails 2 in the first part of the article and later explains the good and bad about them along with some guide on how to use class methods. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Radhames Brito wrote in post #956940:> On Mon, Oct 25, 2010 at 11:52 AM, Marnen Laibow-Koser > <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote: > >> Radhames Brito wrote in post #956904: >> > instead of named scopes use class methods >> > >> > http://www.railway.at/2010/03/09/named-scopes-are-dead/ >> >> That article applies only to Rails 3. The OP said he was using Rails >> 2.3. Therefore, your advice is irrelevant. >> >> > not irrelevant as he can use class methods anyway and is are more > flexible, > i posted the link with general info on scopes as you can see the author > praises scopes in rails 2 in the first part of the article and later > explains the good and bad about them along with some guide on how to use > class methods.Yes. The class method tricks he''s talking about only work with Arel, so they are irrelevant for a standard installation of Rails 2. Some of his complaints also seem a bit specious... Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.