Skip to content

Commit

Permalink
Properly render nested relationship base errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklandgrebe committed Feb 13, 2017
1 parent e964acb commit 17dc96f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/caprese/adapter/json_api/json_pointer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ module JsonPointer
# @param [Object,Array<Object>]
def new(pointer_type, record, value)
if pointer_type == :relationship_attribute
value.to_s.split('.').inject('') do |pointer, v|
values = value.to_s.split('.')
last_index = values.count - 1

values.each_with_index.inject('') do |pointer, (v, i)|
pointer +
if record.class.reflections.key?(v)
record =
Expand All @@ -41,7 +44,11 @@ def new(pointer_type, record, value)
record.send(v)
end

format(POINTERS[:relationship_attribute], v)
if i == last_index
format(POINTERS[:relationship_base], v)
else
format(POINTERS[:relationship_attribute], v)
end
else
format(POINTERS[:attribute], v)
end
Expand Down

0 comments on commit 17dc96f

Please sign in to comment.