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

Setting belongsTo relation will not change hasDirtyAttributes #5138

Closed
hamzahio opened this issue Aug 18, 2017 · 3 comments
Closed

Setting belongsTo relation will not change hasDirtyAttributes #5138

hamzahio opened this issue Aug 18, 2017 · 3 comments

Comments

@hamzahio
Copy link

Setting belongsTo relation will not change hasDirtyAttributes to true

if I have models/book.js

import DS from 'ember-data';

export default DS.Model.extend({
  name            : DS.attr('string'),
  author          : DS.belongsTo('author')
});

and I have models/author.js

import DS from 'ember-data';

export default DS.Model.extend({
  name            : DS.attr('string'),
  bio             : DS.attr('string'),
});

if I do this

this.set("model.author",author);
this.get("model.hasDirtyAttributes") // return false;

the relationship changed but model not changing hasDirtyAttributes

DEBUG: -------------------------------
DEBUG: Ember             : 2.15.0-beta.3
DEBUG: Ember Data        : 2.15.0-beta.4
DEBUG: jQuery            : 3.2.1
DEBUG: Ember Simple Auth : 1.4.0
DEBUG: -------------------------------
@dknutsen
Copy link

This has actually been an issue for a long time. I just ran into it recently and there's a long string of issues which eventually lead to this rfc and a couple of pull requests but unfortunately there doesn't seem to be much movement.

If you need a solution immediately there are a couple of addons you could try but barring that I guess it's just wait and see 🤷‍♂️

@Bartheleway
Copy link
Contributor

You could simply consider that your record is dirty when you enter your edit route and reload then record when you leave if you haven't hit the save button.

I also agree that this is kind of annoying but looking at the links @dknutsen posted, the general use case seems really complicate to handle.

@runspired
Copy link
Contributor

Closing as a duplicate of #2455 (which we also elected to close). As noted, relationship rollback is a non-trivial problem.

That said, @hjdivad and I have some thoughts on a potential path for at least providing a signal to the relationship state for when it has been saved, which is much better than we do today.

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

4 participants