Class: ApplicationViewRecord

Inherits:
ApplicationRecord show all
Defined in:
app/models/application_view_record.rb

Overview

Abstract base class for all database view models.

This class provides:

  1. Read replica routing - queries go to replica in production/staging
  2. Write protection - prevents accidental INSERT/UPDATE/DELETE
  3. Consistent behavior for all view models

Usage:
class ViewProductCatalog < ApplicationViewRecord
# ...
end

All 74 view models inherit from this class to ensure consistent
read replica routing and write protection.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Class Method Details

.createObject

Override to provide better error message

Raises:

  • (ActiveRecord::ReadOnlyRecord)


34
35
36
# File 'app/models/application_view_record.rb', line 34

def self.create(*)
  raise ActiveRecord::ReadOnlyRecord, "#{name} is a read-only view and cannot be written to"
end

.create!Object

Raises:

  • (ActiveRecord::ReadOnlyRecord)


38
39
40
# File 'app/models/application_view_record.rb', line 38

def self.create!(*)
  raise ActiveRecord::ReadOnlyRecord, "#{name} is a read-only view and cannot be written to"
end

Instance Method Details

#readonly?Boolean

Prevent accidental writes to views
This is a safety net - PostgreSQL would reject the write anyway

Returns:

  • (Boolean)


29
30
31
# File 'app/models/application_view_record.rb', line 29

def readonly?
  true
end