Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON: serialize empty arrays to nil #68

Merged
merged 2 commits into from
Jan 23, 2024
Merged

Conversation

matthinea
Copy link
Contributor

@matthinea matthinea commented Jan 17, 2024

Problem

In 85ef44b we changed Array types so that empty arrays are serialized to the database as nil. However, we didn't do this for JSON types, which is the type used by nest_many attributes.

Solution

Serialize empty arrays as nil to the database.

For Platform this means that update statements go from this:

UPDATE "places"
SET "document" = ((document - 'primary_contact') || '{"contacts":[],"contacts_count":0,"updated_at":"2024-01-16T23:44:48.913779Z","extended_contacts_count":0}')
WHERE id = '427622700'

to this:

UPDATE "places"
SET "document" = ((((document - 'contacts') - 'contacts_count') - 'primary_contact') || '{"updated_at":"2024-01-17T00:50:33.987526Z","extended_contacts_count":0}')
WHERE id = '427622700'

test/unit/types/json_type_test.rb Outdated Show resolved Hide resolved
test/unit/types/json_type_test.rb Outdated Show resolved Hide resolved
test/unit/types/json_type_test.rb Outdated Show resolved Hide resolved
@matthinea matthinea merged commit d9a3bfa into master Jan 23, 2024
1 check passed
@matthinea matthinea deleted the serialize-empty-json-as-nil branch January 23, 2024 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants