app/models/user_team.rb
# == Schema Information
#
# Table name: user_teams
#
# id :bigint not null, primary key
# role :integer default("member"), not null
# created_at :datetime not null
# updated_at :datetime not null
# team_id :bigint not null
# user_id :bigint not null
#
# Indexes
#
# index_user_teams_on_team_id (team_id)
# index_user_teams_on_user_id (user_id)
# index_user_teams_on_user_id_and_team_id (user_id,team_id) UNIQUE
#
# Foreign Keys
#
# fk_rails_... (team_id => teams.id)
# fk_rails_... (user_id => users.id)
#
class UserTeam < ApplicationRecord
belongs_to :user
belongs_to :team
validates :user_id, uniqueness: { scope: :team_id }
enum role: { member: 0, manager: 1, observer: 2 }
scope :managers, -> { where(role: :manager) }
scope :has_team_access, -> { where.not(role: :member) }
def self.ransackable_attributes(_auth_object = nil)
%w[created_at id id_value role team_id updated_at user_id]
end
end