2021-08-10 20:10:03 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class CustomerRelations::Organization < ApplicationRecord
|
2021-08-20 05:09:16 -04:00
|
|
|
include StripAttribute
|
|
|
|
|
2021-08-10 20:10:03 -04:00
|
|
|
self.table_name = "customer_relations_organizations"
|
|
|
|
|
|
|
|
belongs_to :group, -> { where(type: 'Group') }, foreign_key: 'group_id'
|
|
|
|
|
2021-08-20 05:09:16 -04:00
|
|
|
strip_attributes! :name
|
2021-08-10 20:10:03 -04:00
|
|
|
|
|
|
|
enum state: {
|
|
|
|
inactive: 0,
|
|
|
|
active: 1
|
|
|
|
}
|
|
|
|
|
|
|
|
validates :group, presence: true
|
|
|
|
validates :name, presence: true
|
|
|
|
validates :name, uniqueness: { case_sensitive: false, scope: [:group_id] }
|
|
|
|
validates :name, length: { maximum: 255 }
|
|
|
|
validates :description, length: { maximum: 1024 }
|
|
|
|
|
|
|
|
def self.find_by_name(group_id, name)
|
|
|
|
where(group: group_id)
|
|
|
|
.where('LOWER(name) = LOWER(?)', name)
|
|
|
|
end
|
|
|
|
end
|