Skip to content

Instantly share code, notes, and snippets.

@Mongey
Created March 12, 2012 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mongey/2019558 to your computer and use it in GitHub Desktop.
Save Mongey/2019558 to your computer and use it in GitHub Desktop.
class Employee < ActiveRecord::Base
has_many :timeslots
scope :free_time, lambda {|day| joins(:timeslots).merge(Timeslot.on(day)) }
end
class Timeslot < ActiveRecord::Base
belongs_to :employee
scope :on, lambda { |this_date| where("start >= ? AND end <= ?", this_date, this_date+ 1.day)}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment