One model's data replaced with another model's data despite distinct names!

  • 1
  • Problem
  • Updated 2 years ago
  • In Progress
Terrible and strange problem.

Why would the data from one model be replacing the data from a distinct model when i attempt a save?



I've only been able to reproduce this issue with these two models, but I've had users report the 'disappearing name' in other circumstances as well. 

If it helps, here's the snippet behind that save button:

'saveAllSnippet': function () {
var modelsToSave = [],
modelsToExclude = ['AddTests','ProcessLog','ChangeTracker','ShowTabs','UI_Model','DefaultTo','ChartAudit'],
dfd = new $.Deferred();
$.each(skuid.model.map(), function(){
if (this.hasChanged && (modelsToExclude.indexOf(this.id) === -1) && this.preventUnloadIfUnsavedChanges) {
modelsToSave.push(this);
}
});
$.when(skuid.model.save(modelsToSave))
.done(function(result){
console.log('All Models Saved.');
dfd.resolve(result);
})
.fail(function(result){
console.log('All Model Save Failed.');
dfd.reject(result);
});
return dfd.promise();
},
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb

Posted 2 years ago

  • 1
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Did you try saving without using the snippet to see what happens?
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Good idea, Pat.
When I save the ReturnHQInteraction model separately, it works as expected.

In fact, when I include both models in a manual save (in any order), it seems to work just fine:
skuid.model.save([skuid.$M('ReturnHQInteraction'),skuid.$M('Interaction')])
skuid.model.save([skuid.$M('Interaction'),skuid.$M('ReturnHQInteraction')])
^^^those both work fine.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
If I run a basic version of the same saveAllSnippet in the console it works fine:

var $=skuid.$, modelsToSave = [],			modelsToExclude = ['AddTests','ProcessLog','ChangeTracker','ShowTabs','UI_Model','DefaultTo','ChartAudit'];
$.each(skuid.model.map(), function(){
if (this.hasChanged && (modelsToExclude.indexOf(this.id) === -1) && this.preventUnloadIfUnsavedChanges) {
modelsToSave.push(this);
}
});
$.when(skuid.model.save(modelsToSave))
.done(function(result){
console.log('All Models Saved.');
})
.fail(function(result){
console.log('All Model Save Failed.');
});
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
I'd step through the code in your snippet one line at a time and inspect after each.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Ok, I was wrong about my last two posts. it looks like things are consistently going wrong as described in the OP when there are changes in both models and they are saved in the same skuid.model.save() call.

The only field that is usually changed in the parent page Interaction model is a ui-only field, if that matters?
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
I've had a similar issue with ui only field. Making it read-only fixes the issue for me.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
If I make a ui-only field read only, I can still update it with javascript, right?
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Yup
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Ok, skuid. I have a valid workaround, but it would be nice to know if this is on your radar to fix at some point?

When a model has changes only to ui-only fields and is saved in the same action as another model with real database changes, the data from the second model is replacing the data in the first.