Method: HaveAPI::ModelAdapters::ActiveRecord::Action::InstanceMethods#ar_parse_includes

Defined in:
lib/haveapi/model_adapters/active_record.rb

#ar_parse_includes(raw) ⇒ Object

Parse includes sent by the user and return them in an array of symbols and hashes.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/haveapi/model_adapters/active_record.rb', line 46

def ar_parse_includes(raw)
  return @ar_parsed_includes if @ar_parsed_includes
  @ar_parsed_includes = ar_inner_includes(raw).select do |inc|
    # Drop associations that are not registered in the AR:
    #   The API resource may have associations that are not based on
    #   associations in AR.
    if inc.is_a?(::Hash)
      inc.each_key do |k|
        next(false) unless self.class.model.reflections.has_key?(k.to_s)
      end

    else
      next(false) unless self.class.model.reflections.has_key?(inc.to_s)
    end

    true
  end
end