Class: AttrJson::Associations::Loader::HasCollection

Inherits:
Base
  • Object
show all
Defined in:
lib/attr_json/associations/loader/has_collection.rb

Direct Known Subclasses

HasMany, HasOne

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from AttrJson::Associations::Loader::Base

Instance Method Details

#loadObject



8
9
10
11
12
13
14
15
16
# File 'lib/attr_json/associations/loader/has_collection.rb', line 8

def load
  value = @record.public_send(@assoc.primary_key)
  if value.present?
    @assoc.scoped.merge(target_scope(@assoc.foreign_key, value))
                 .merge(target_order(@assoc.foreign_key, value))
  else
    @assoc.klass.none
  end
end