mongoid-cached-json icon indicating copy to clipboard operation
mongoid-cached-json copied to clipboard

`hide_as_child_json_when` makes null mean two things & weird API asymmetry

Open craigspaeth opened this issue 12 years ago • 0 comments

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 partner in each of them because the gallery isn't public.
  • I click "feature artwork" which PUTs the JSON I just got with feature_eligible set to true.
  • This also PUTS partner: null which 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.

craigspaeth avatar Mar 11 '13 20:03 craigspaeth