class NoBrainer::Document::Association::HasManyThrough::Metadata

Constants

VALID_OPTIONS

Public Instance Methods

eager_load(docs, additional_criteria=nil) click to toggle source
# File lib/no_brainer/document/association/has_many_through.rb, line 17
def eager_load(docs, additional_criteria=nil)
  criteria = target_model.instance_exec(&options[:scope]) if options[:scope]
  criteria = criteria ? criteria.merge(additional_criteria) : additional_criteria if additional_criteria
  NoBrainer::Document::Association::EagerLoader
    .eager_load_association(through_association.eager_load(docs), target_name, criteria)
end
target_model() click to toggle source
# File lib/no_brainer/document/association/has_many_through.rb, line 24
def target_model
  meta = through_association.target_model.association_metadata
  association = meta[target_name.to_sym] || meta[target_name.to_s.singularize.to_sym]
  association.target_model
end
through_association() click to toggle source
# File lib/no_brainer/document/association/has_many_through.rb, line 12
def through_association
  owner_model.association_metadata[through_association_name] or
    raise "#{through_association_name} association not found"
end
through_association_name() click to toggle source
# File lib/no_brainer/document/association/has_many_through.rb, line 8
def through_association_name
  options[:through].to_sym
end