Class: CustomerRelations::Organization
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- CustomerRelations::Organization
- Includes:
- Gitlab::SQL::Pattern, Sortable, StripAttribute
- Defined in:
- app/models/customer_relations/organization.rb
Constant Summary
Constants included from Gitlab::SQL::Pattern
Gitlab::SQL::Pattern::MIN_CHARS_FOR_PARTIAL_MATCHING, Gitlab::SQL::Pattern::REGEX_QUOTED_TERM
Constants inherited from ApplicationRecord
Constants included from HasCheckConstraints
HasCheckConstraints::NOT_NULL_CHECK_PATTERN
Constants included from ResetOnColumnErrors
ResetOnColumnErrors::MAX_RESET_PERIOD
Class Method Summary collapse
- .counts_by_state ⇒ Object
- .default_state_counts ⇒ Object
- .find_by_name(group_id, name) ⇒ Object
-
.search(query) ⇒ Object
Searches for organizations with a matching name or description.
- .search_by_state(state) ⇒ Object
- .sort_by_field(field, direction) ⇒ Object
- .sort_by_name ⇒ Object
Methods included from StripAttribute
Methods included from Gitlab::SQL::Pattern
Methods inherited from ApplicationRecord
===, cached_column_list, #create_or_load_association, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
Methods included from Organizations::Sharding
Methods included from ResetOnColumnErrors
#reset_on_union_error, #reset_on_unknown_attribute_error
Methods included from Gitlab::SensitiveSerializableHash
Class Method Details
.counts_by_state ⇒ Object
62 63 64 |
# File 'app/models/customer_relations/organization.rb', line 62 def self.counts_by_state default_state_counts.merge(group(:state).count) end |
.default_state_counts ⇒ Object
68 69 70 71 72 |
# File 'app/models/customer_relations/organization.rb', line 68 def self.default_state_counts states.keys.index_with do |key| 0 end end |
.find_by_name(group_id, name) ⇒ Object
57 58 59 60 |
# File 'app/models/customer_relations/organization.rb', line 57 def self.find_by_name(group_id, name) where(group: group_id) .where('LOWER(name) = LOWER(?)', name) end |
.search(query) ⇒ Object
Searches for organizations with a matching name or description.
This method uses ILIKE on PostgreSQL
query - The search query as a String
Returns an ActiveRecord::Relation.
37 38 39 |
# File 'app/models/customer_relations/organization.rb', line 37 def self.search(query) fuzzy_search(query, [:name, :description], use_minimum_char_limit: false) end |
.search_by_state(state) ⇒ Object
41 42 43 |
# File 'app/models/customer_relations/organization.rb', line 41 def self.search_by_state(state) where(state: state) end |
.sort_by_field(field, direction) ⇒ Object
45 46 47 48 49 50 51 |
# File 'app/models/customer_relations/organization.rb', line 45 def self.sort_by_field(field, direction) if direction == :asc order_scope_asc(field) else order_scope_desc(field) end end |
.sort_by_name ⇒ Object
53 54 55 |
# File 'app/models/customer_relations/organization.rb', line 53 def self.sort_by_name order(name: :asc) end |