Conditions on Has_many :Through

so i have a bunch of users
this bit of code gets all the schedules for a particular user. i’m
wondering if there’s a way for me to get only a range of schedules based
on the time field for the user without having to get all the schedules
assigned to the user the user then stepping through the time for every
schedule.

this is the bit now.

    @blab = User.find(session[:user].id).myschedules

   -step through each schedule that the user has and check to make

sure that the schedule is in the specified date and time range before
displaying each schedule. (yes i know this is very sloppy.

i would like to be able to
@blab = User.find(session[:user].id).myschedules.find(from
1200am to 9pm)

   -step throught each schedule that the user has.

or something to that effect

btw myschedules the has_many through relationship.

nobody?

You should do something like this:

first of all I’d suggest you remove MY from model’s name (so instead
of MySchedules to be only Schedule).

In Schedule model (schedule.rb) you have to make a finder:

def self.between(from, to)
self.find :all, :conditions => [“happens_on BETWEEN ? AND ?”, from,
to]
end

Then you can do find like this:

person = Person.find 1
person.schedules.between(@from, @to)

Hope this helps.
On 8 avg., 17:15, Morgan M. [email protected]

you can use a named scope for that