Class: ProjectAuthorization

Inherits:
ApplicationRecord show all
Extended by:
SuppressCompositePrimaryKeyWarning
Includes:
FromUnion
Defined in:
app/models/project_authorization.rb

Constant Summary

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Class Method Summary collapse

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, 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 SensitiveSerializableHash

#serializable_hash

Class Method Details

.insert_all(attributes) ⇒ Object

This method overrides its ActiveRecord's version in order to work correctly with composite primary keys and fix the tests for Rails 6.1

Consider using BulkInsertSafe module instead since we plan to refactor it in gitlab.com/gitlab-org/gitlab/-/issues/331264


25
26
27
# File 'app/models/project_authorization.rb', line 25

def self.insert_all(attributes)
  super(attributes, unique_by: connection.schema_cache.primary_keys(table_name))
end

.insert_all_in_batches(attributes, per_batch = 1000) ⇒ Object


29
30
31
32
33
# File 'app/models/project_authorization.rb', line 29

def self.insert_all_in_batches(attributes, per_batch = 1000)
  attributes.each_slice(per_batch) do |attributes_batch|
    insert_all(attributes_batch)
  end
end

.select_from_union(relations) ⇒ Object


14
15
16
17
18
# File 'app/models/project_authorization.rb', line 14

def self.select_from_union(relations)
  from_union(relations)
    .select(['project_id', 'MAX(access_level) AS access_level'])
    .group(:project_id)
end