I fixed the problem eventually but it was not obvious how.

----------------------
app/models/schedule.rb
----------------------
 39   # --
 40   # Return all coliding
 41   # events
 42   #
 43   def coliding_events
 44     cs = []
 45
 46     # Id's of schedules with overlapping times of day
 47     pcsids = possibly_coliding_schedules.map &:id
 48
 49     if pcsids.size == 0
 50       return []
 51     end
 52
 53     e0 = Event.arel_table
 54     e1 = Event.arel_table.alias # because we do a self join
 55
 56     # compare self events
 57     j0 = e0[:schedule_id].eq(id)
 58
 59     # and find events on the same dates
 60     j1 = e0[:start_at].eq(e1[:start_at])
 61
 62     # whose times of day are overlapping
 63     j2 = e1[:schedule_id].in(pcsids)
 64
 65
 66     q = e0.join(e1).on(j1)
 67     Event.joins(q.join_sql).where(j0.and(j2))
 68   end

You need to use the join_sql method on the Arel object and pass that to the
active record joins method. I also
explicity used an 'on' clause.

At the moment the documentation seems pretty thin on using Arel directly
within active record.

--
Brad Phelan
http://xtargets.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 [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