Forum: Ruby on Rails How to reuse named scope conditions with eager loading

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2b2b07fe8688479d2559704d4bf8a264?d=identicon&s=25 Szymon Nowak (szimek)
on 2009-03-12 17:38
(Received via mailing list)
Hi,

I've got Channel model that has many events. Event belongs to channel
and additionally has a named scope called "current".

I need to iterate over each channel and then over each "current" event
for given channel i.e.:

@channels.each do |channel|
  channel.events.current do |event|
    ...
  end
end

I could do

@channels = Channel.all(:include => :events, :conditions =>
"events.end_time >...")

but the problem is that the conditions would be exactly the same as
already specified for the "current" scope in Event model. Is it
somehow possible to reuse them here?
This topic is locked and can not be replied to.