Skip to content

Instantly share code, notes, and snippets.

@brycesenz
Created January 8, 2016 20:18
Show Gist options
  • Save brycesenz/e96cf0fe5d83a130a305 to your computer and use it in GitHub Desktop.
Save brycesenz/e96cf0fe5d83a130a305 to your computer and use it in GitHub Desktop.
Salaries
class PayStub
belongs_to :salary
attr_accessor :start_date, :end_date
end
class Salary
belongs_to :user
has_many :pay_stubs
def historic_pay_stubs(to_date, end_date)
pay_stubs.select do |stub|
stub.start_date >= to_date && stub.end_date <= end_date
end
end
end
class User
has_many :salaries
has_many :pay_stubs, through: :salaries
def historic_pay_stubs(to_date, end_date)
pay_stubs.select do |stub|
stub.start_date >= to_date && stub.end_date <= end_date
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment