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

Add support for to_json #643

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Add support for to_json #643

wants to merge 2 commits into from

Conversation

bonekost
Copy link

@bonekost bonekost commented Jul 23, 2024

This PR fixes a regression that I noticed in ActiveRecord::Base#as_json return value. (same as #630)

Description

If you enable attribute_methods plugin, mobility patches ActiveRecord::Base#attributes method to include translated attributes as wekk. The same change used to apply to ActiveRecord::Base#as_json too.

But the internal implementation of serialization changed slightly in Rails 7.0 to improve the performance.

As a result, as_json method no longer includes translated attributes.

Solution

I added an override of attribute_names_for_serialization method into the plugin to make it include the missing translated fields into serialized_attributes hash which is used by as_json later.

attribute_names_for_serialization would be never be called by Rails 6.x or lower, but I still added a safe guard against calling super.

@ollym
Copy link

ollym commented Jul 23, 2024

@shioyama this is a rebase + changelog for #630 as that PR seemed to stop

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