Tricky Model association

I’ve got a tricky (at least for me) model association I need to
establish. Here are the two tables

Appointment
id, name, start(datetime), stop(datetime)
1, apt1, 1/4/2011 14:00, 1/4/2011 14:30
Schedule
id, name, start(datetime), stop(datetime)
1, sch1, 1/4/2011 08:00, 1/4/2011 17:00

I need to associate a schedule with an appointment. So each
appointment will have_one schedule. The assocation get’s created by
virtue of the start/stop of the appointment being in between the start/
stop of a schedule.

This sql will return the record

select *
from apts a
inner join schedules s on s.start <= a.start and s.stop >= a.stop

So what do I do?
class Apt < ActiveRecord::Base
has_one :schedule, something here
end

:finder_sql => “sql”

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs