<commit_before># frozen_string_literal: true

# == Schema Information
#
# Table name: group_members
#
#  id         :integer          not null, primary key
#  groupid    :integer
#  userid     :integer
#  leader     :boolean
#  created_at :datetime
#  updated_at :datetime
#

class GroupMember < ApplicationRecord
  after_destroy :destroy_meeting_memberships

  validates :groupid, :userid, presence: true
  validates :leader, inclusion: [true, false]

  belongs_to :group, foreign_key: :groupid, inverse_of: :group_member
  belongs_to :user, foreign_key: :userid, inverse_of: :group_member

  has_many :meetings, through: :group
  has_many :meeting_memberships,
           lambda(group_member) {
             where(meeting_members: { userid: group_member.userid })
           },
           through: :meetings, source: :meeting_members

  def destroy_meeting_memberships
    # this can't be done through dependent: :destroy because nested associations<commit_msg>Use correct multiline lambda syntax<commit_after># frozen_string_literal: true

# == Schema Information
#
# Table name: group_members
#
#  id         :integer          not null, primary key
#  groupid    :integer
#  userid     :integer
#  leader     :boolean
#  created_at :datetime
#  updated_at :datetime
#

class GroupMember < ApplicationRecord
  after_destroy :destroy_meeting_memberships

  validates :groupid, :userid, presence: true
  validates :leader, inclusion: [true, false]

  belongs_to :group, foreign_key: :groupid, inverse_of: :group_member
  belongs_to :user, foreign_key: :userid, inverse_of: :group_member

  has_many :meetings, through: :group
  has_many :meeting_memberships,
           lambda { |group_member|
             where(meeting_members: { userid: group_member.userid })
           },
           through: :meetings, source: :meeting_members

  def destroy_meeting_memberships
    # this can't be done through dependent: :destroy because nested associations
{'fraction_non_alphanumeric': 0.08209338122113904, 'fraction_numerical': 0.0, 'mean_word_length': 3.7794117647058822, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '892547', 'n_tokens_mistral': 597, 'n_tokens_neox': 577, 'n_words': 158}