Sha256: 570f15172df3cb9dcf99f5fd6d049aa4894db3efebf57dd42eeb4f183b5a6129

Contents?: true

Size: 967 Bytes

Versions: 14

Compression:

Stored size: 967 Bytes

Contents

# Memberships are the relationship between groups and participants
# The important note here is that there is only ONE ACTIVE
# Membership for each participant at a time
class Membership < ActiveRecord::Base
  include ThinkFeelDoDashboard::Concerns::Membership

  belongs_to :group
  belongs_to :active_group,
             class_name: "Group",
             foreign_key: :group_id,
             inverse_of: :active_memberships
  belongs_to :participant
  belongs_to :active_participant,
             class_name: "Participant",
             foreign_key: :participant_id,
             inverse_of: :active_membership

  validates :group, :participant, presence: true
  validates :group_id,
            uniqueness: { scope: :participant_id, message: "has already been assigned to this participant." }

  scope :active, lambda {
    where("start_date <= ? OR start_date = ?", Time.zone.today, nil)
    .where("end_date >= ? OR end_date = ?", Time.zone.today, nil)
  }

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
think_feel_do_dashboard-1.2.1 spec/dummy/app/models/membership.rb
think_feel_do_dashboard-1.2.0.beta1 spec/dummy/app/models/membership.rb
think_feel_do_dashboard-1.1.21 spec/dummy/app/models/membership.rb
think_feel_do_dashboard-1.1.20 spec/dummy/app/models/membership.rb
think_feel_do_dashboard-1.1.19 spec/dummy/app/models/membership.rb
think_feel_do_dashboard-1.1.18 spec/dummy/app/models/membership.rb
think_feel_do_dashboard-1.1.17 spec/dummy/app/models/membership.rb
think_feel_do_dashboard-1.1.16 spec/dummy/app/models/membership.rb
think_feel_do_dashboard-1.1.15 spec/dummy/app/models/membership.rb
think_feel_do_dashboard-1.1.14 spec/dummy/app/models/membership.rb
think_feel_do_dashboard-1.1.13 spec/dummy/app/models/membership.rb
think_feel_do_dashboard-1.1.12 spec/dummy/app/models/membership.rb
think_feel_do_dashboard-1.1.11 spec/dummy/app/models/membership.rb
think_feel_do_dashboard-1.1.10 spec/dummy/app/models/membership.rb