-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
JSONAdapter: Collision with internal properties should throw warning #6611
Comments
By any chance, is there a different path from which I can |
@Redsandro 👋 Glad you found the issue. Which one "won" - the ember-data property or your property? Also, luckily, this is tracked privately with
|
data/packages/record-data/addon/-private/record-data.ts Lines 298 to 300 in 9a67f6a
I can't believe I haven't found that! I should have used that. Seems like a 1 char serializer fix. I never really check out the underscored parameters when inspecting (anymore) because those change sometimes without notice. But in this case it would have been a quick fix.
The Ember Data property won 😅 I changed all refs in my app. |
Not sure if I should close this because I understand what happened, or keep this open because everyone can step into the same trap, especially since #confusion |
In the past there has been more or less the same complaint about other properties, so some tests were added: https://github.com/emberjs/data/blob/master/packages/-ember-data/tests/unit/model-test.js#L703. Here it seems like a different case, but I don't know if properties like isNew (which are defined as readOnly (
Also maybe when RecordData features are on, this problem will disappear by itself. cc @runspired |
Maybe we also could add some checks, like https://github.com/emberjs/data/blob/master/packages/model/addon/-private/model.js#L1399 |
A few things:
For non-attrs, snapshot does give you access to the record it is a snapshot for, so you can serialize any non-attributes that way via direct access. For changed attrs snapshot gives you
|
Ember data
JSONAdapter
lacks the ability toPATCH
only dirty attributes. One way to work around this is to use the automatically inserted state attributes (i.e.isNew
) in your serializer:However, when (accidentally) using such a key in your model, no warning is given that an internally set key is overwritten, causing problems with state-related functionality.
It took me some time to figure out that my own code was to blame, indicating of course that, contrary to what my mother used to say, I'm not the smartest person in the world. I had completely forgotten this computed property and the model was not in my frame of reference when hunting for the problem.
Humans are prone to this kind of mistakes. I suggest that either the internally set parameters are prepended with an underscore to signify their status, or show a warning when internally set parameters are overwritten in the model.
Versions
The text was updated successfully, but these errors were encountered: