Class: Lutaml::Qea::Models::BaseModel

Inherits:
Model::Serializable
  • Object
show all
Defined in:
lib/lutaml/qea/models/base_model.rb

Overview

Abstract base model for all QEA database models Provides common behavior and interface for domain models

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_db_row(row) ⇒ BaseModel

Create instance from database row hash Handles case-insensitive column name mapping from database

Parameters:

  • row (Hash)

    database row with string keys

Returns:



35
36
37
38
39
40
41
42
43
44
# File 'lib/lutaml/qea/models/base_model.rb', line 35

def self.from_db_row(row)
  return nil if row.nil?

  # Convert database column names to attribute names
  attrs = row.transform_keys do |key|
    key.to_s.downcase.to_sym
  end

  new(attrs)
end

.primary_key_columnSymbol

Abstract method to be implemented by subclasses

Returns:

  • (Symbol)

    the primary key column name

Raises:

  • (NotImplementedError)


13
14
15
16
# File 'lib/lutaml/qea/models/base_model.rb', line 13

def self.primary_key_column
  raise NotImplementedError,
        "#{self} must implement .primary_key_column"
end

.table_nameString

Abstract method to be implemented by subclasses

Returns:

  • (String)

    the database table name

Raises:

  • (NotImplementedError)


20
21
22
23
# File 'lib/lutaml/qea/models/base_model.rb', line 20

def self.table_name
  raise NotImplementedError,
        "#{self} must implement .table_name"
end

Instance Method Details

#primary_keyObject

Returns the primary key value for this instance

Returns:

  • (Object)

    the primary key value



27
28
29
# File 'lib/lutaml/qea/models/base_model.rb', line 27

def primary_key
  send(self.class.primary_key_column)
end