debian-mirror-gitlab/app/models/customer_relations/organization.rb

28 lines
695 B
Ruby
Raw Normal View History

2021-10-27 15:23:28 +05:30
# frozen_string_literal: true
class CustomerRelations::Organization < ApplicationRecord
2021-11-11 11:23:49 +05:30
include StripAttribute
2021-10-27 15:23:28 +05:30
self.table_name = "customer_relations_organizations"
2021-11-18 22:05:49 +05:30
belongs_to :group, -> { where(type: Group.sti_name) }, foreign_key: 'group_id'
2021-10-27 15:23:28 +05:30
2021-11-11 11:23:49 +05:30
strip_attributes! :name
2021-10-27 15:23:28 +05:30
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