mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Add include_data :if_sideloaded (#1931)
For JSONAPI, `include_data` currently means, "should we populate the 'data'" key for this relationship. Current options are true/false. This adds the `:if_sideloaded` option. This means "only populate the 'data' key when we are sideloading this relationship." This is because 'data' is often only relevant to sideloading, and causes a database hit. Addresses https://github.com/rails-api/active_model_serializers/issues/1555
This commit is contained in:
committed by
L. Preston Sego III
parent
6ed499f38e
commit
2145540795
@@ -83,7 +83,8 @@ module ActiveModel
|
||||
# +default_include_directive+ config value when not provided)
|
||||
# @return [Enumerator<Association>]
|
||||
#
|
||||
def associations(include_directive = ActiveModelSerializers.default_include_directive)
|
||||
def associations(include_directive = ActiveModelSerializers.default_include_directive, include_slice = nil)
|
||||
include_slice ||= include_directive
|
||||
return unless object
|
||||
|
||||
Enumerator.new do |y|
|
||||
@@ -91,7 +92,8 @@ module ActiveModel
|
||||
next if reflection.excluded?(self)
|
||||
key = reflection.options.fetch(:key, reflection.name)
|
||||
next unless include_directive.key?(key)
|
||||
y.yield reflection.build_association(self, instance_options)
|
||||
|
||||
y.yield reflection.build_association(self, instance_options, include_slice)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user