Created
December 14, 2010 01:46
-
-
Save thedelchop/739889 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ActiveMembership < ActiveRecord::Base | |
belongs_to :member | |
has_many :active_membership_motions | |
has_one :qualifying_motion, :through => :active_membership_motions, | |
:source => :motion, | |
:conditions => {:active_membership_motions => {:qualifying => true}} | |
has_one :disqualifying_motion, :through => :active_membership_motions, | |
:source => :motion, | |
:conditions => {:active_membership_motions => {:qualifying => false}} | |
validates :qualifying_motion, :presence => true | |
# Finds all active memberships for a given time | |
# @param [Date, Time, DateTime] time The Date and Time in which to search for active memberships | |
# @return [Array] The list of active memberships, which were active at a given time | |
def self.active_at(time) | |
where("started_at <= ?", time). | |
where("ended_at >= ? OR ended_at IS NULL", time) | |
end | |
# Finds all members active at a given date or date+time | |
# @param [Date, Time, DateTime] time The Date and Time in which to search for active members | |
# @return [Array] A unique list of members, active at the given time | |
def self.members_active_at(time) | |
members = active_at(time).map(&:member) | |
members.uniq | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment