Class: DataAPI::DataModel

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/data_api/data_model.rb

Class Method Summary collapse

Class Method Details

.set_owner_relationObject

Sets the owner relation in needed


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/data_api/data_model.rb', line 14

def self.set_owner_relation
  if owned_by_user
    case owner_primary_key
    when 'id'
      belongs_to :owner, class_name: User, primary_key: :id, foreign_key: owner_foreign_key
    when 'uuid'
      belongs_to :owner, class_name: User, primary_key: :uuid, foreign_key: owner_foreign_key
    when 'email'
      belongs_to :owner, class_name: User, primary_key: :email, foreign_key: owner_foreign_key
    when 'uid'
      belongs_to :owner_identity, ->(o) { where(organization_code: o.class.organization_code) },
                 class_name: UserIdentity, primary_key: :uid, foreign_key: owner_foreign_key
      has_one :owner, class_name: :User, through: :owner_identity, source: :user
    end
  end
end

.test_db_connectionObject

Try to establish the database connection


32
33
34
35
36
37
# File 'app/models/data_api/data_model.rb', line 32

def self.test_db_connection
  remove_connection
  establish_connection database_url
rescue ActiveRecord::ActiveRecordError => e
  Rails.logger.error e
end