lib/dato/json_api_serializer.rb in dato-0.7.15 vs lib/dato/json_api_serializer.rb in dato-0.7.16
- old
+ new
@@ -21,14 +21,12 @@
end
data[:type] = type
data[:attributes] = serialized_attributes(resource)
- serialized_relationships = serialized_relationships(resource)
-
- if serialized_relationships
- data[:relationships] = serialized_relationships
+ if relationships.any?
+ data[:relationships] = serialized_relationships(resource)
end
{ data: data }
end
@@ -82,11 +80,11 @@
elsif required_relationships.include?(relationship)
throw "Required attribute: #{relationship}"
end
end
- result.empty? ? nil : result
+ result
end
def attributes(resource)
if type == 'item'
return resource.keys.map(&:to_sym) - %i[
@@ -110,14 +108,10 @@
def relationships
@relationships ||= JsonSchemaRelationships.new(link.schema).relationships
end
def required_relationships
- if link.schema.properties['data'].required.include?("relationships")
- (link_relationships.required || []).map(&:to_sym)
- else
- []
- end
+ (link_relationships.required || []).map(&:to_sym)
end
def link_attributes
link.schema.properties['data'].properties['attributes']
end