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.

Constant Summary

Constants included from Schedulable

Schedulable::SIMPLE_FORM_OPTIONS

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 Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Class Method Details

.createObject

Override to provide better error message

Raises:

  • (ActiveRecord::ReadOnlyRecord)


32
33
34
# File 'app/models/application_view_record.rb', line 32

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

.create!Object

Raises:

  • (ActiveRecord::ReadOnlyRecord)


36
37
38
# File 'app/models/application_view_record.rb', line 36

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)


27
28
29
# File 'app/models/application_view_record.rb', line 27

def readonly?
  true
end