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

method to tell if a model needs saving #2347

Closed
calvinmetcalf opened this issue Oct 6, 2014 · 6 comments
Closed

method to tell if a model needs saving #2347

calvinmetcalf opened this issue Oct 6, 2014 · 6 comments

Comments

@calvinmetcalf
Copy link
Contributor

as far as I can tell isDirty is the only way to tell if a model has been changed, but that does not get triggered if you change a belongsTo relationship, e.g.

//models/person.js
export default DS.Model.extend({
  employer: DS.belongsTo('company'),
  largeData: DS.attr()
});

// somewhere else

person.set('employer', somethingElse);
person.get('isDirty');//false

I ended up having to write this

function actuallyDirty(model) {
    if (model.get('isDirty')) {
      return true;
    }
    var state = false;
    model.eachRelationship(function (rel) {
      if ((model._data[rel] && model._data[rel].id) !== model.get(rel + '.id')) {
        state = true;
      }
    });
    return state;
  }
@nwjsmith
Copy link

nwjsmith commented Oct 9, 2014

I believe this is a dup of #1367

@calvinmetcalf
Copy link
Contributor Author

the ask here is for a way to tell if it's been changed, not necessarily having isDirty apply to relationships.

@DougPuchalski
Copy link

+1 I'm noticing also that rollback doesn't reset a belongsTo back to the persisted value (as it's not added to _inFlightAttributes).

@knownasilya
Copy link
Contributor

areRelationshipsDirty and another one that is dirtyRelationships which returns an array of dirty relationships, either strings or the actual objects. Probably strings, attribute names.

@timrwood
Copy link

I've opened an RFC for this issue. Please weigh in.

emberjs/rfcs#21

@igorT
Copy link
Member

igorT commented May 25, 2015

Tracking this under #2122

@igorT igorT closed this as completed May 25, 2015
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

6 participants