Syntax for child with alias and condition is unexpected
child foo: :bar, if: true is going to call
data_object with {foo: :bar, if: true}, so then check on size == 1 will fail and :bar wont be taken into account.
https://github.com/nesquena/rabl/blob/master/lib/rabl/helpers.rb#L12
The same happens for me. It is annoying because you can't aliase a child field and use if: at the same time. There is any workaround?
This ticket needs renamed to be noticed, IMO.
The issue is that because child() can take a 'data' field (first param) that is a hash, data_object will not grab the proper data field (the key in the hash in this case) if there is a second parameter that is also a hash (like an if clause)
My workaround is to wrap the child node in a regular if/end
attributes :one, :two, :three
if root_object.has_four?
child(root_object.four => :four) do
attributes :fourohone, :fourohtwo
end
end
You could probably also do:
child({ :foo => :bar }, { :if => true } do
# ...
end
Not ideal but that should work as well. Renamed ticket to reflect the issue.
Feel free to rename, or suggest your name. What is misleading in current title?
+1