Breeze seems to be reverting the fkey property value when the query expands the associated navigation property -- even when using the preserveChange merge strategy. We need a way to preserve all changes.
Steps: Modify an fkey property of an entity in the cache. Query from the server with expand for the associated nav prop. When the query completes (data merged), the fkey property value is the saved value (was reverted).
To demonstrate the problem I ran the following code fragment two times. The first time loads the cache and modifies entities[0].ProjectAreaRef from 1 to 48. The second time performs the same query to test merging. After the 2nd query orig is 48 and val is 1. The change in the cached entity was overwritten.
var query = new breeze.EntityQuery().from('Issue');
query = query.expand('oProjectArea');
entityManager.executeQuery(query).then(function (x) {
var entities = x.results;
var val = entities[0].ProjectAreaRef;
if (orig && val !== orig)
console.log('orig:' + orig + ' val:' + val);
entities[0].ProjectAreaRef = 48;
I guess one might say that expanding into a nav prop is asking to refresh the relationship. Otherwise, the parent entity retrieved (based on the fkey value on the server) might no longer be associated with the child entity. But, that’s fine for us. Let the parent entity be merged into the cache even though it’s no longer associated with the child entity.
Regardless of whether this is a breeze feature or a bug (IMO it's a bug), how can I get breeze to preserve changes to fkey properties? If it's a bug, do you know of a workaround? If it's a feature, is there another feature that allows me to use expand() while preserving changes to fkey properties?
Using latest version: 1.5.3 ... although same behavior in 1.4.11.
preserveChanges
is the default. Are you even touching it? Meanwhile, we'll try a quick repro here – Ward