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

saveChanges doesn't flush changed attributes #17

Open
Leooo opened this issue May 26, 2017 · 11 comments
Open

saveChanges doesn't flush changed attributes #17

Leooo opened this issue May 26, 2017 · 11 comments

Comments

@Leooo
Copy link

Leooo commented May 26, 2017

After using appointment.saveChanges(), I still see attributes in appointments.changed(), coming from appointment.changedAttributes().

Calling appointment._internalModel.flushChangedAttributes() would solve the problem.

@danielspaniel
Copy link
Owner

are you using auto track or manual mode? if manual mode you have to call model.startTrack() before you edit.

@Leooo
Copy link
Author

Leooo commented May 26, 2017

changeTracker: {trackHasMany: true, auto: true, enableIsDirty: true},

@Leooo
Copy link
Author

Leooo commented May 26, 2017

Ember & Ember-data 2.10

@danielspaniel
Copy link
Owner

ok .. so can you post a brief summary of code ( how you are using change tracker ) so I can see the full context.

@Leooo
Copy link
Author

Leooo commented May 26, 2017

appointment.save().then(() => {
        appointment.set('status', 'open');
        appointment.saveChanges();//changed() still shows the `status` attribute changed
        appointment._internalModel.flushChangedAttributes();//changed() is now empty
..

@Leooo
Copy link
Author

Leooo commented May 26, 2017

As above, other than that I only have this line in my appointment model:

changeTracker: {trackHasMany: true, auto: true, enableIsDirty: true},

btw being able to see old and new hasMany relationship when doing changed() (that we can see for attributes) would be awesome.

@danielspaniel
Copy link
Owner

Is this the test you are showing me? or application code?
What you going to have to do to have me help you is to clone the repo and make a failing test that shows the bug .. or shows this situation ( which I can not see right now )
Because my tests ( if you look them over ) are pretty extensive.

You might have found a whacky situation that I did not cover. But I don't see it offhand.

I used to show the changed for belongsTo / hasMany .. and it could be probably brought back as an option ?? I took it out because it could get ugly with more than 50 items. But for people using small data sets it is great.

@Leooo
Copy link
Author

Leooo commented May 26, 2017

@danielspaniel I understand. I will try to build a test case but not sure I will have time.

Right now I have another issue where none of the model-ext attributes are present on the model when pushing a new model instance to the store in a unit test, that I will try to fix too:

      appointment = store.push({
        data: [{
          id: '666',
          type: modelName,
          attributes: {},
          relationships: {}
        }]
      })[0];
      appointment.saveChanges();//failing, appointment.saveChanges is undefined

@Leooo
Copy link
Author

Leooo commented May 26, 2017

strangely, the above is failing only when I run the unit tests for the model only, without other tests. When I run the whole test suite the test is passing because the ember-data-change-tracker initializer is run, but the initializer is not run when I just run the model unit test.

EDIT: got it to work by manually launching the initializer in my unit test, like in your unit tests: import {initializer as modelInitializer} from 'ember-data-change-tracker';

@Leooo
Copy link
Author

Leooo commented May 26, 2017

@danielspaniel added failing test in #18

@Leooo
Copy link
Author

Leooo commented Oct 22, 2019

equivalent fix for ED >= 3.5: this._internalModel.__recordData.didCommit()

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

No branches or pull requests

2 participants