The fiddle shows the problem
On init we have ```users``` list containing 3 items. We use standard findOne to get new data from server that contains new list, and we want old list to be replaced by new one.
By default old list is merged with new one. If not use ```removeAttr: false``` option for Model, lists will be merged definitely incorrectly. So the only option is use ```removeAttr: true```, but not sure it if its a safe option, as may lead to unexpected removal of some attributes in nested maps.
What is the option without using ```removeAttr: true```?
Fiddle code:
- var Todo = can.Model.extend({
- removeAttr: false //dont' want to use this for whole model
- },{
- });
- //to place model in store set _reqs
- can.Model._reqs = 1;
- var todo = new Todo({
- id: 1,
- title: 'title',
- users: [{name: 'John', last: 'Galt'}, {name: 'Henk', last: 'Rearden'}, {name: 'Alex'}]
- })
- console.log('todo before update:', todo.users.length)
- // let say then I've got new users data from server using findOne
- // I don't want to mess with fixtures for this example, so Todo.model function will be called at the end of findOne
- var newData = {id:1, users: [{name: 'Dagny'}, {name: 'Jane'}]}
- Todo.model(newData)
- // this function will merge old users with new users and it will be mess user will have 3 items, but should have olny 2.
- console.log('todo after update:', todo.users.length, todo.users.serialize())