Class: AmsLazyRelationships::Loaders::SimpleHasMany

Inherits:
Base
  • Object
show all
Defined in:
lib/ams_lazy_relationships/loaders/simple_has_many.rb

Overview

Batch loads ActiveRecord records belonging to given record by foreign key. Useful when the relationship is not a standard ActiveRecord relationship.

Instance Method Summary collapse

Methods inherited from Base

#load

Constructor Details

#initialize(association_class_name, foreign_key:) ⇒ SimpleHasMany

Returns a new instance of SimpleHasMany.

Parameters:

  • association_class_name (String)

    Name of the ActiveRecord class e.g. in case when loading blog_post.comments it’d be “Comment”

  • foreign_key (Symbol)

    association’s foreign key. e.g. in case when loading blog_post.comments it’d be :blog_post_id



14
15
16
17
# File 'lib/ams_lazy_relationships/loaders/simple_has_many.rb', line 14

def initialize(association_class_name, foreign_key:)
  @association_class_name = association_class_name
  @foreign_key = foreign_key.to_sym
end