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

multiple calls to peekAll and unloadAll put store into inconsistent state #5167

Closed
bantic opened this issue Sep 6, 2017 · 4 comments · Fixed by #5378
Closed

multiple calls to peekAll and unloadAll put store into inconsistent state #5167

bantic opened this issue Sep 6, 2017 · 4 comments · Fixed by #5378

Comments

@bantic
Copy link
Member

bantic commented Sep 6, 2017

This seems similar to #5111, perhaps a duplicate.

edit: First observed using ember data version 2.14.11 and reproduced on 2.16.0-canary.

I have 2 models, one of which hasMany of the other, and I noticed that after repeating a flow that involved calling unloadAll to remove the child elements and then pushPayload to add new ones, the store started reporting inconsistent results for both peekAll and parentModel.get('childModels.length').

For example, if the models are Person and Car and Person has-many cars (and car belongs-to person), the following code puts the store into the inconsistent state:

let person = store.createRecord('person');
store.push({ data: { type: 'car', id: '1'}});
store.peekAll('car').forEach(car => car.set('person', person));
console.log(person.get('cars.length')); // 1, as expected

store.unloadAll('car');
console.log(store.peekAll('car').get('length')); // 0, expected
console.log(person.get('cars.length')); // 0, expected

// load the car again
store.push({data: { type: 'car', id: '1'}});
store.peekAll('car').forEach(car => car.set('person', person));
console.log(store._internalModelsFor('car')); // 0! (should be: 1)
console.log(person.get('cars.length')); // 0! (should be: 1)

store.unloadAll('car');
console.log(store.peekAll('car').get('length')); // 1! (should be: 0)

This unexpected behavior appears to be related to using peekAll + forEach to set the parent property on the peeked records. If the lines in the code snippet above that call car.set('person', person) are removed, things behave as expected.

bantic added a commit to bantic/data that referenced this issue Sep 6, 2017
@bantic
Copy link
Member Author

bantic commented Sep 6, 2017

Failing test: #5168

bantic added a commit to bantic/data that referenced this issue Sep 6, 2017
@workmanw
Copy link

workmanw commented Sep 6, 2017

It seems related to me also. I also have #5157 which could be a different flavor of the same problem.

@mqje
Copy link

mqje commented Sep 11, 2017

Hello, I think have a similar issue with the unloadAll() method. I am trying to unload some 'type' with this method :

const self = this;
['type1', 'type2', 'type3'].forEach((type) => {
self.get('store').unloadAll(type);
});

But it doesn't seems to unload my record at all, the only way I find out to unload my record is :

self.get('store').unloadAll();

This method work, but I'm losing some other record in my store too, which is something not intended.

Also, it worked with [email protected].
I am currently on 2.15, and it doesn't work.

@runspired
Copy link
Contributor

I confirmed that this is fixed by #5378 and added a test in case it were to resurface.

bmac pushed a commit that referenced this issue Mar 26, 2018
* [BUGFIX] resolve issues with RecordArray sync for peekAll

* remove unneeded part of fix

* Adds a test for #5167

* add test and fix for #5350

* port test from #5095

* fix filter test for older versions of Ember
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

Successfully merging a pull request may close this issue.

4 participants