0
votes

Here's what I current have, OData backend, AngularJS using breezejs on the front end. The app is a cordova app and will work offline so I need to store what I have in the breeze cache somewhere. My choice is currently indexeddb.

I am exporting each entities into its own store in indexeddb which works absolutely fine. I can re import all these entities individually as well. The issue comes when I create an entity offline (so will have a temp key, eg -1) when I am importing the entities I get an error

entity Customer TypeError: Cannot read property 'values' of null

This appears to be due to foreign key issue when breeze does its fix up of id's but I can't figure out how to get round this.

I've tried importing the entities in a certain order ect.

If i export the whole lot in one string and reimport it in one string then it works fine with the newly created entities but I am reaching some size constraints hence the splitting up of the entities.

1

1 Answers

1
votes

You have correctly identified the issue.

The problem is that breeze needs to fix up temporary foreign keys when it imports entities. This is normally handled by exporting and importing the entire EntityManager which contains information needed to do the temp key fixup. When you export just the entity itself you lose this information because it isn't 'entity' level, it's actually entityManager level and the entityManager keeps track of all 'temp' keys in a single place.

So your option is to either eliminate the use of temp keys when you export and import or store the entire entityManager ( or a subset entity manager that just contains changes) in a single indexdb cache item.

Does this make sense?