mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Fix nested include attributes
When the requests asked for a nested attribute in the `include` and it's missing or empty, don't break because the type of the object can't be determined. If the request is for a collection and none of the elements has the attribute, it will not be added to the `linked` key, similar to what happens with simple includes.
This commit is contained in:
@@ -68,8 +68,8 @@ module ActiveModel
|
||||
|
||||
resource_path = [parent, resource_name].compact.join('.')
|
||||
|
||||
if include_assoc?(resource_path)
|
||||
plural_name = serialized_object_type(serializers).pluralize.to_sym
|
||||
if include_assoc?(resource_path) && resource_type = serialized_object_type(serializers)
|
||||
plural_name = resource_type.pluralize.to_sym
|
||||
@top[:linked] ||= {}
|
||||
@top[:linked][plural_name] ||= []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user