From 1edd559bb8162076d2d00b50cce4061f655b8f33 Mon Sep 17 00:00:00 2001 From: Arnt Gulbrandsen Date: Tue, 15 Dec 2015 20:37:28 +0000 Subject: [PATCH] Half-new relationship option: always_include_linkage_data The option existed (undocumented) for has_one. This change documents it and implements it for has_many as well. --- README.md | 1 + lib/jsonapi/resource_serializer.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index 39e083b25..3e3ef08f9 100644 --- a/README.md +++ b/README.md @@ -450,6 +450,7 @@ The relationship methods (`relationship`, `has_one`, and `has_many`) support the * `acts_as_set` - allows the entire set of related records to be replaced in one operation. Defaults to false if not set. * `polymorphic` - set to true to identify relationships that are polymorphic. * `relation_name` - the name of the relation to use on the model. A lambda may be provided which allows conditional selection of the relation based on the context. + * `always_include_linkage_data` - if set to true, the relationship includes linkage data. Defaults to false if not set. `to_one` relationships support the additional option: * `foreign_key_on` - defaults to `:self`. To indicate that the foreign key is on the related resource specify `:related`. diff --git a/lib/jsonapi/resource_serializer.rb b/lib/jsonapi/resource_serializer.rb index 9122cd776..6cdea59ec 100644 --- a/lib/jsonapi/resource_serializer.rb +++ b/lib/jsonapi/resource_serializer.rb @@ -278,6 +278,7 @@ def link_object_to_one(source, relationship, include_linkage) end def link_object_to_many(source, relationship, include_linkage) + include_linkage = include_linkage | relationship.always_include_linkage_data link_object_hash = {} link_object_hash[:links] = {} link_object_hash[:links][:self] = self_link(source, relationship)