Sprankelprachtig aan/afmeldsysteem

group.rb 866B

12345678910111213141516171819202122232425262728293031323334
  1. # A Group contains Members, which can organize and participate in Activities.
  2. # Some of the Members may be group leaders, with the ability to see all
  3. # information and add or remove members from the group.
  4. class Group < ApplicationRecord
  5. # @!attribute name
  6. # @return [String]
  7. # the name of the group. Must be unique across all groups.
  8. has_many :members
  9. has_many :people, through: :members
  10. has_many :activities
  11. validates :name,
  12. presence: true,
  13. uniqueness: {
  14. case_sensitive: false
  15. }
  16. # @return [Array<Member>] the members in the group who are also group leaders.
  17. def leaders
  18. self.members.includes(:person).where(is_leader: true)
  19. end
  20. # Determine whether the passed person is a group leader.
  21. def is_leader?(person)
  22. Member.exists?(
  23. person: person,
  24. group: self,
  25. is_leader: true
  26. )
  27. end
  28. end