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:
Lee Richmond
2016-09-25 12:57:19 -04:00
committed by L. Preston Sego III
parent 6ed499f38e
commit 2145540795
6 changed files with 204 additions and 28 deletions

View File

@@ -30,6 +30,7 @@ module ActiveModel
# Make JSON API top-level jsonapi member opt-in
# ref: http://jsonapi.org/format/#document-top-level
config.jsonapi_include_toplevel_object = false
config.include_data_default = true
config.schema_path = 'test/support/schemas'
end