12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- class Member < ApplicationRecord
-
-
-
- belongs_to :person
- belongs_to :group
- after_create :create_future_participants!
- before_destroy :delete_future_participants!
- validates :person_id,
- uniqueness: {
- scope: :group_id,
- message: I18n.t('groups.member.already_in')
- }
-
-
- def create_future_participants!
- activities = self.group.future_activities
- unless self.person.activities.empty?
- activities = activities.where(
- 'activities.id NOT IN (?)', self.person.activities.ids
- )
- end
- activities.each do |a|
- Participant.create!(
- activity: a,
- person: self.person
- )
- end
- end
-
-
- def delete_future_participants!
- participants = Participant.where(
- person_id: self.person.id,
- activity: self.group.future_activities
- )
- participants.each do |p|
- p.destroy!
- end
- end
- end
|