Module: ActiveRecordCustomPreloader
- Defined in:
- lib/active_record_custom_preloader/with_context_dependent_loading.rb,
lib/active_record_custom_preloader.rb,
lib/active_record_custom_preloader/version.rb,
lib/active_record_custom_preloader/preloader.rb,
lib/active_record_custom_preloader/model_patch.rb,
lib/active_record_custom_preloader/relation_patch.rb,
lib/active_record_custom_preloader/preload_with_options.rb,
lib/active_record_custom_preloader/associations_preloader.rb,
lib/active_record_custom_preloader/with_array_foreign_keys_loading.rb,
lib/active_record_custom_preloader/with_multiple_foreign_keys_loading.rb
Overview
Usage example:
class Employee < ApplicationRecord
# columns: id, name, department_id, position_id
add_custom_loader :_contract, class_name: 'EmployeeContractPreloader'
end
class Contract < ApplicationRecord
# columns: id, text, employee_department_id, position_id
end
class EmployeeContractPreloader < ActiveRecordCustomPreloader::Preloader
include ActiveRecordCustomPreloader::WithMultipleForeignKeysLoading
self.model_class_name = 'Contract'
self.association_foreign_keys_names = [:employee_department_id, :position_id]
def record_foreign_keys(record)
[record.department_id, record.position_id]
end
end
Defined Under Namespace
Modules: ModelPatch, RelationPatch, WithArrayForeignKeysLoading, WithContextDependentLoading, WithMultipleForeignKeysLoading Classes: AssociationsPreloader, Error, PreloadWithOptions, Preloader
Constant Summary collapse
- VERSION =
'2.0.0'