rails / jbuilder

Jbuilder: generate JSON objects with a Builder-style DSL
MIT License
4.34k stars 440 forks source link

Single nil object should be treated as nil #439

Open sr189 opened 6 years ago

sr189 commented 6 years ago

In response to #350

Jbuilder is currently returning an empty array when using a partial with a single object association such as:

json.organisation @order.organisation, partial: 'organisations/organisation', as: :organisation

This behaviour was introduced by #148 in order to return an empty array in case a collection is return nil. However this behaviour leads to the fact that all nil values are rendered as an empty array even if the association does not represent a collection or the more precise collection argument is used.

rails-bot commented 6 years ago

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @pixeltrix (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.