mongoid-cached-json
mongoid-cached-json copied to clipboard
`hide_as_child_json_when` makes null mean two things & weird API asymmetry
Using hide_as_child_json_when means that the API returns null to mean two different things 1. If the relation doesn't exist, 2. Some arbitrary clause e.g. The relation isn't "public".
I think hide_as_child_json_when should return something other than null or not include that key in the JSON at all.
Here's a concrete example of why this is weird:
- I GET all of an upcoming show's artworks. This returns null for
partnerin each of them because the gallery isn't public. - I click "feature artwork" which PUTs the JSON I just got with
feature_eligibleset to true. - This also PUTS
partner: nullwhich removes the relationship to the gallery... now the gallery thinks the artwork was deleted.
To work around this the client has to know or assume null can mean multiple things and compensate by manipulating the fetched JSON to not sync the partner field unless the user explicitly breaks that relationship.
It's not hard to work around, but I thought this was an odd design decision.