Chatwoot/app/models/conversation_participant.rb

41 lines
1.1 KiB
Ruby
Raw Normal View History

2022-03-08 20:43:14 +00:00
# == Schema Information
#
# Table name: conversation_participants
#
# id :bigint not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# account_id :bigint not null
# conversation_id :bigint not null
# user_id :bigint not null
#
# Indexes
#
# index_conversation_participants_on_account_id (account_id)
# index_conversation_participants_on_conversation_id (conversation_id)
# index_conversation_participants_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (account_id => accounts.id) ON DELETE => cascade
# fk_rails_... (conversation_id => conversations.id) ON DELETE => cascade
# fk_rails_... (user_id => users.id) ON DELETE => cascade
#
class ConversationParticipant < ApplicationRecord
validates :account_id, presence: true
validates :conversation_id, presence: true
validates :user_id, presence: true
belongs_to :account
belongs_to :conversation
belongs_to :user
before_validation :ensure_account_id
private
def ensure_account_id
self.account_id = conversation&.account_id
end
end