Class: JsonApiModel::Associations::Preloaders::Has
- Defined in:
- lib/json_api_model/associations/preloaders/has.rb
Instance Attribute Summary
Attributes inherited from Base
#base_class, #key, #name, #opts
Instance Method Summary collapse
Methods inherited from Base
#association_class, #fetch, #initialize, #json_relationship?, #process
Constructor Details
This class inherits a constructor from JsonApiModel::Associations::Base
Instance Method Details
#associated_key(object) ⇒ Object
5 6 7 8 9 |
# File 'lib/json_api_model/associations/preloaders/has.rb', line 5 def associated_key( object ) object.respond_to?( key ) ? object.send( key ) : object.id rescue => e nil end |
#query(instances) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/json_api_model/associations/preloaders/has.rb', line 11 def query( instances ) instances.each_with_object( { key => [] } ) do | instance, query | query[ key ] += Array( ids( instance ) ) query[ key ].uniq! end end |