-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
.toJSON not including getterMethods #10997
Comments
That's because of this breaking change #9568 Lines 3318 to 3323 in 2c50b7e
If you add VIRTUAL field fullName instead of getter, then request it in attributes ['firstName', 'lastName', 'fullName'] , it would work.But with getter it would fail. |
I've noticed if you add a VIRTUAL field
Not sure if this is good/recommended practice? |
@mjy78 Once this gets fixed, it won't be a good practice. But for now it's a valid workaround, I'd say. Stay tuned. |
@jayarjo When I self-assigned this, my idea was to make every getterMethod appear in the .toJSON() output, just that, very simple. But now I realize this might be technically considered a breaking change...
Yes, it works. I personally prefer this way, even if the other way worked already... Looks cleaner to me (but this is just my opinion). @sushantdhiman Perhaps we could just deprecate getterMethods in favor of virtual fields? What do you think? |
I also prefer VIRTUAL fields, feels cleaner. You should definitely consider deprecating one or the other. |
It would be nice if this was documented in https://github.com/sequelize/sequelize/blob/master/docs/upgrade-to-v5.md, especially if a fix may take a while. |
This is also happening with |
This should definitely be mentioned in the breaking changes. Happy to update the documentation if that's ok? |
When the getters ARE invoked, and they return undefined, it appears that the toJSON() falls on its face! |
This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the "stale" label. 🙂 |
bump |
|
Recently upgraded to v5 from v4. Version
5.8.6
User model with
fullName
getterMethodController endpoint:
Bug:
result
hasfullName
property butresult.toJSON()
does not includefullName
The text was updated successfully, but these errors were encountered: