lib/jsonapi_mapper.rb in jsonapi_mapper-0.1.4 vs lib/jsonapi_mapper.rb in jsonapi_mapper-0.1.7
- old
+ new
@@ -100,12 +100,13 @@
end
relationships = {}
json.fetch(:relationships, {}).each do |name, value|
next unless type.rule.attributes.include?(name)
+ next if value[:data].blank?
relationships[renamed_attr(type.name, name)] = if value[:data].is_a?(Array)
- value[:data].map{|v| build_id(v) }
+ value[:data].map{|v| build_id(v) }
else
build_id(value[:data])
end
end
@@ -170,12 +171,11 @@
(data_mappable + included)
end
def save_all
return false unless all.all?(&:valid?)
- all.each(&:save)
- true
+ all.collect(&:save).all?
end
def all_valid?
all.map(&:valid?).all? # This does not short-circuit, to get all errors.
end
@@ -205,10 +205,10 @@
if collection?
data.each_with_index do |resource, i|
errors << serialize_errors_for("/data/#{i}", resource)
end
- else
+ elsif data
errors << serialize_errors_for("/data", data)
end
included.each_with_index do |resource, i|
errors << serialize_errors_for("/included/#{i}", resource)