Model is returning `hasDirtyAttributes` without any changes


#1

Hi Ember Community,

I am currently having an odd problem when I am attempting to validate my model data. Essentially, I have a set of navigation buttons that allows a user to traverse a navigation bar. The navigation bar is a series of routes, each with their own model, and every page allows you to make changes.The functionality I am after is that before a user can transition to a different route/template, they must ensure their data is saved.

The base functionality is in place except that each time I load the initial model, it starts out dirty. But only! the first model. When I transition between other routes/templates, their models always return clean, no matter what changes I make to the page.

Here is the current code that I am utilizing the get the appropriate model for my route, as well as the current save function:

`export default Route.extend({

navArray : Ember.computed(function() {
return [
    'projects.define.time-period',
    'projects.define.transactions',
    'projects.define.entities',
    'projects.define.geo-hierarchy',
    'projects.define.products',
    'projects.define.metrics',
    'projects.define.filters',
    'projects.define.filter-set'
  ];
}),

actions: {

	save() {
		const flashMessages = this.get('flashMessages');
		let router = Ember.getOwner(this).lookup('router:main');
		let currentRouteName = router.currentRouteName;
		let currentModel = this.modelFor(currentRouteName);
		let changedAttributes = this.get('changedAttributes');

		let navArray = this.get('navArray');

		currentModel.save()
		.then((resolved) => {
			flashMessages.info('Data saved!');
		})
		.catch((err) => {
			flashMessages.danger('Data not saved. Please try again.')
		})
	   },

           next() {
		let router = Ember.getOwner(this).lookup('router:main');
		let currentRouteName = router.currentRouteName;
		let currentModel = this.modelFor(currentRouteName);

		let navArray = this.get('navArray');

		let currentIndex = navArray.indexOf(currentRouteName);
		let nextIndex = currentIndex + 1;

		if (currentModel.isAny('hasDirtyAttributes', true)) {
			$('#validateForward').modal('show');
		}
		else {
			if (currentIndex < navArray.length - 1) {
			  this.transitionTo(navArray.objectAt(nextIndex));
			}
			else {
			    this.transitionTo(navArray.get('firstObject'));
			}
		}
	}
     });` 

I find this to be an odd error. When I click “Save” on the initial template, I have logged that this does in fact change the ‘hasDirtyAttributes’ to false. However when I leave that route and return, the model is dirty once again. It should also be noted that when the next function is run, the modal appears only on the initial template.

I hope you can help, Ember team! I have spent many an hour attempting to debug this issue, and I really want this cool functionality to work!

Brandon