DmitryTsepelev / store_model

Work with JSON-backed attributes as ActiveRecord-ish models
MIT License
1.04k stars 85 forks source link

Fix serialization on nested objects #154

Closed mweitzel closed 1 year ago

mweitzel commented 1 year ago

Fixes #150, which tracks a breaking change in serialization and persistence of json object.

After v1.6.2, nested models received multiple serialization passes. This broke all json queries against the persisted rows. I merged in the test which @trumanshuck used to isolate the version, then added a fix from there.

This PR removes values_for_database and patches as_json so nested Hash and StoreModel attributes will only serialized as JSON once. For array attributes, it delegates to as_json, so they are safe as well.

This ensures: