-
Notifications
You must be signed in to change notification settings - Fork 44
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
Unchanged hasMany causing isDirty #28
Comments
Just discovered that if I make a second change to the "deliverables" field, I don't get a change in the "subscribers"
|
I can't tell you why this is happening because I don't know what you are doing. I would need to see the whole picture of what is going on, from start to finish. |
I also experience a similar issue. Assume a model |
oooo .. this sounds like a bug. |
I have an example project that demonstrates this issue.
Open your browser http://localhost:4200 The first problem you will notice is that To replicate the problem described in this issue:
|
Thanks Bryan for writeup and this repo with bug example. It would be nice to have a failing test in change tracker repo, and hopefully I can make one on my own with your setup in this repo you made. |
what you are doing is: loading all tasks ( in application route ) the task already exists so ember data just takes the comments and slaps them on the existing task, meaning now the comments are added and the relationship is dirty, since you just added comments to a task. this would be no big deal IF ember data called the didUpdate hook for this kind of update ( new payload info ). But it does NOT and I think it is a bug. Change tracker will call saveChanges for you when/if the didUpdate hook is called. ( Problem solved ) So, ember-data does NOT fire the didUpdate hook when it updates a model with pushPayload ( which is happening when you loading task again with comments included ) since all it is really doing is pushing more data to one of the existing tasks that you loaded from the application route. to solve your problem you simply have to do this: // routes/task.js
// make a custom setupController method. once the task model is ready and loaded.
// it would be nice if ember-data fired the didUpdate method, but since it does not,
// you have to saveChanges() on the model manually and here is the perfect place to do it.
setupController(controller, model) {
model.saveChanges();
controller.setProperties({model});
} make sense? |
@danielspaniel Thx for clarifying this! But one question remains to me: This works for a 'standard' model - how would this work for an RSVP.hash? E.g.
modelA is the one with the dirty relationship. I did try
but this did not bring the expected result... |
You have to be more specific about what result your talking about .. I can guess, but I have to be super sure. If you can put this example in your repo and update it and tell me what you expect ( exactly ) then I can tell you what I think can be done |
I'm using ember-data-change-tracker inside a custom adapter linking ember data with Spring data REST. It's solved my issue of observing changes to relationships and automatically making the correct API calls on However, I've seen this issue in my code. When an async belongsTo or hasMany is loaded and auto tracking is true, that relationship is considered to be 'changed', i.e. I've written some code to reset the relationship tracking on load Here is a unit test snippet that illustrates the problem
Here is an initializer that reopens the Store and makes the fix
It seems to work, but I'm not entirely sure I'm happy making modifications to behaviour in 2 libraries simultaneously (i.e. both ember-data and ember-data-change-tracker). It would be great if this feature was offered by default inside the addon. |
wow .. this is blast from the past. but i would suggest you make a PR and write a test or make the fix in the change tracker repo, that way I can check it out and see if it makes sense. I still don't follow the test and for sure you can't do a fix where you open the ember-data store. that not going to make anyone happy. but if you can do a better fix or explain the issue in a test ( in change tracker ) then I happy to check it out |
I've done some digging and found the route cause. Details and tests in #66 The behaviour of ember-data-change-tracker is closely linked to the chosen serialization format between the UI and the server. When resource linkage for associations is present in the response the association is not dirty on load, but when resource linkage is missing then the association becomes dirty on load |
I'm working on some code to autosave my model. It looks like:
I have the model configured with:
changeTracker: { trackHasMany: true, auto: true, enableIsDirty: true }
When I change a string "deliverables" attribute in the model, I get on the console:
Why does it think subscribers changed? subscribers is modeled as:
subscribers: hasMany('user', {inverse: null})
The text was updated successfully, but these errors were encountered: