chore: Add contact note model (#2462)

This commit is contained in:
Muhsin Keloth
2021-06-21 15:16:26 +05:30
committed by GitHub
parent f809431074
commit 3d748aa8d4
8 changed files with 96 additions and 0 deletions

View File

@@ -37,6 +37,7 @@ class Account < ApplicationRecord
has_many :data_imports, dependent: :destroy
has_many :users, through: :account_users
has_many :inboxes, dependent: :destroy
has_many :notes, dependent: :destroy
has_many :campaigns, dependent: :destroy
has_many :conversations, dependent: :destroy
has_many :messages, dependent: :destroy

View File

@@ -41,6 +41,7 @@ class Contact < ApplicationRecord
has_many :contact_inboxes, dependent: :destroy
has_many :inboxes, through: :contact_inboxes
has_many :messages, as: :sender, dependent: :destroy
has_many :notes, dependent: :destroy
before_validation :prepare_email_attribute
after_create_commit :dispatch_create_event, :ip_lookup

34
app/models/note.rb Normal file
View File

@@ -0,0 +1,34 @@
# == Schema Information
#
# Table name: notes
#
# id :bigint not null, primary key
# content :text not null
# created_at :datetime not null
# updated_at :datetime not null
# account_id :bigint not null
# contact_id :bigint not null
# user_id :bigint
#
# Indexes
#
# index_notes_on_account_id (account_id)
# index_notes_on_contact_id (contact_id)
# index_notes_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (account_id => accounts.id)
# fk_rails_... (contact_id => contacts.id)
# fk_rails_... (user_id => users.id)
#
class Note < ApplicationRecord
validates :content, presence: true
validates :account_id, presence: true
validates :contact_id, presence: true
validates :user_id, presence: true
belongs_to :account
belongs_to :contact
belongs_to :user
end

View File

@@ -82,6 +82,7 @@ class User < ApplicationRecord
has_many :notification_subscriptions, dependent: :destroy
has_many :team_members, dependent: :destroy
has_many :teams, through: :team_members
has_many :notes, dependent: :nullify
before_validation :set_password_and_uid, on: :create