Chatwoot/app/models/note.rb

38 lines
897 B
Ruby
Raw Normal View History

2021-06-21 09:46:26 +00:00
# == 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)
#
class Note < ApplicationRecord
2021-10-24 07:10:30 +00:00
before_validation :ensure_account_id
2021-06-21 09:46:26 +00:00
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
2021-10-24 07:10:30 +00:00
scope :latest, -> { order(created_at: :desc) }
2021-10-24 07:10:30 +00:00
private
def ensure_account_id
self.account_id = contact&.account_id
end
2021-06-21 09:46:26 +00:00
end