Skip to content

Commit

Permalink
fix for D2677 - Problem with MergeStrategy.PreserveChanges with fk ch…
Browse files Browse the repository at this point in the history
…ange and expand.
  • Loading branch information
jtraband committed May 7, 2015
1 parent 0169f73 commit 4352e05
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 21 deletions.
19 changes: 15 additions & 4 deletions build/breeze.base.debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -6174,7 +6174,8 @@ var JsonResultsAdapter = (function () {
entityType: entityType,
nodeId: node.$id,
nodeRefId: node.$ref,
ignore: ignore
ignore: ignore,
passThru: false // default
};
}
});
Expand Down Expand Up @@ -15486,10 +15487,10 @@ var MappingContext = (function () {
if (typeof relatedEntity === 'function') {
mc.deferredFns.push(function () {
relatedEntity = relatedEntity();
updateRelatedEntityInCollection(relatedEntity, originalRelatedEntities, targetEntity, inverseProperty);
updateRelatedEntityInCollection(mc, relatedEntity, originalRelatedEntities, targetEntity, inverseProperty);
});
} else {
updateRelatedEntityInCollection(relatedEntity, originalRelatedEntities, targetEntity, inverseProperty);
updateRelatedEntityInCollection(mc, relatedEntity, originalRelatedEntities, targetEntity, inverseProperty);
}
});
}
Expand Down Expand Up @@ -15540,11 +15541,21 @@ var MappingContext = (function () {
}
}

function updateRelatedEntityInCollection(relatedEntity, relatedEntities, targetEntity, inverseProperty) {
function updateRelatedEntityInCollection(mc, relatedEntity, relatedEntities, targetEntity, inverseProperty) {
if (!relatedEntity) return;

// don't update relatedCollection if preserveChanges & relatedEntity has an fkChange.
if (relatedEntity.entityAspect.entityState === EntityState.Modified
&& mc.mergeOptions.mergeStrategy === MergeStrategy.PreserveChanges) {
var origValues = relatedEntity.entityAspect.originalValues;
var fkWasModified = inverseProperty.relatedDataProperties.some(function(dp) {
return origValues[dp.name] != undefined;
});
if (fkWasModified) return;
}
// check if the related entity is already hooked up
var thisEntity = relatedEntity.getProperty(inverseProperty.name);

if (thisEntity !== targetEntity) {
// if not - hook it up.
relatedEntities.push(relatedEntity);
Expand Down
2 changes: 1 addition & 1 deletion build/breeze.base.min.js

Large diffs are not rendered by default.

19 changes: 15 additions & 4 deletions build/breeze.debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -6174,7 +6174,8 @@ var JsonResultsAdapter = (function () {
entityType: entityType,
nodeId: node.$id,
nodeRefId: node.$ref,
ignore: ignore
ignore: ignore,
passThru: false // default
};
}
});
Expand Down Expand Up @@ -15486,10 +15487,10 @@ var MappingContext = (function () {
if (typeof relatedEntity === 'function') {
mc.deferredFns.push(function () {
relatedEntity = relatedEntity();
updateRelatedEntityInCollection(relatedEntity, originalRelatedEntities, targetEntity, inverseProperty);
updateRelatedEntityInCollection(mc, relatedEntity, originalRelatedEntities, targetEntity, inverseProperty);
});
} else {
updateRelatedEntityInCollection(relatedEntity, originalRelatedEntities, targetEntity, inverseProperty);
updateRelatedEntityInCollection(mc, relatedEntity, originalRelatedEntities, targetEntity, inverseProperty);
}
});
}
Expand Down Expand Up @@ -15540,11 +15541,21 @@ var MappingContext = (function () {
}
}

function updateRelatedEntityInCollection(relatedEntity, relatedEntities, targetEntity, inverseProperty) {
function updateRelatedEntityInCollection(mc, relatedEntity, relatedEntities, targetEntity, inverseProperty) {
if (!relatedEntity) return;

// don't update relatedCollection if preserveChanges & relatedEntity has an fkChange.
if (relatedEntity.entityAspect.entityState === EntityState.Modified
&& mc.mergeOptions.mergeStrategy === MergeStrategy.PreserveChanges) {
var origValues = relatedEntity.entityAspect.originalValues;
var fkWasModified = inverseProperty.relatedDataProperties.some(function(dp) {
return origValues[dp.name] != undefined;
});
if (fkWasModified) return;
}
// check if the related entity is already hooked up
var thisEntity = relatedEntity.getProperty(inverseProperty.name);

if (thisEntity !== targetEntity) {
// if not - hook it up.
relatedEntities.push(relatedEntity);
Expand Down
2 changes: 1 addition & 1 deletion build/breeze.intellisense.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated on: Tue May 05 2015 11:11:05 GMT-0700 (Pacific Daylight Time)
// Generated on: Thu May 07 2015 14:06:22 GMT-0700 (Pacific Daylight Time)
intellisense.annotate(breeze.core, {
'Enum': function() {
/// <signature>
Expand Down
4 changes: 2 additions & 2 deletions build/breeze.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion docs/api-docs/classes/JsonResultsAdapter.html
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ <h4>Example:</h4>
entityType: entityType,
nodeId: node.$id,
nodeRefId: node.$ref,
ignore: ignore
ignore: ignore,
passThru: false // default
};
}
});
Expand Down
2 changes: 1 addition & 1 deletion docs/api-docs/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -3869,7 +3869,7 @@
"line": 206,
"description": "JsonResultsAdapter constructor",
"example": [
"\n //\n var jsonResultsAdapter = new JsonResultsAdapter({\n name: \"test1e\",\n extractResults: function(json) {\n return json.results;\n },\n visitNode: function(node, mappingContext, nodeContext) {\n var entityType = normalizeTypeName(node.$type);\n var propertyName = nodeContext.propertyName;\n var ignore = propertyName && propertyName.substr(0, 1) === \"$\";\n\n return {\n entityType: entityType,\n nodeId: node.$id,\n nodeRefId: node.$ref,\n ignore: ignore\n };\n }\n });\n\n var dataService = new DataService( {\n serviceName: \"breeze/foo\",\n jsonResultsAdapter: jsonResultsAdapter\n });\n\n var entityManager = new EntityManager( {\n dataService: dataService\n });"
"\n //\n var jsonResultsAdapter = new JsonResultsAdapter({\n name: \"test1e\",\n extractResults: function(json) {\n return json.results;\n },\n visitNode: function(node, mappingContext, nodeContext) {\n var entityType = normalizeTypeName(node.$type);\n var propertyName = nodeContext.propertyName;\n var ignore = propertyName && propertyName.substr(0, 1) === \"$\";\n\n return {\n entityType: entityType,\n nodeId: node.$id,\n nodeRefId: node.$ref,\n ignore: ignore,\n passThru: false // default\n };\n }\n });\n\n var dataService = new DataService( {\n serviceName: \"breeze/foo\",\n jsonResultsAdapter: jsonResultsAdapter\n });\n\n var entityManager = new EntityManager( {\n dataService: dataService\n });"
],
"itemtype": "method",
"name": "<ctor> JsonResultsAdapter",
Expand Down
3 changes: 2 additions & 1 deletion docs/api-docs/files/.._src_a40_dataService.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ <h1 class="file-heading">File: ..\src\a40_dataService.js</h1>
entityType: entityType,
nodeId: node.$id,
nodeRefId: node.$ref,
ignore: ignore
ignore: ignore,
passThru: false // default
};
}
});
Expand Down
16 changes: 13 additions & 3 deletions docs/api-docs/files/.._src_a55_mappingContext.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,10 @@ <h1 class="file-heading">File: ..\src\a55_mappingContext.js</h1>
if (typeof relatedEntity === &#x27;function&#x27;) {
mc.deferredFns.push(function () {
relatedEntity = relatedEntity();
updateRelatedEntityInCollection(relatedEntity, originalRelatedEntities, targetEntity, inverseProperty);
updateRelatedEntityInCollection(mc, relatedEntity, originalRelatedEntities, targetEntity, inverseProperty);
});
} else {
updateRelatedEntityInCollection(relatedEntity, originalRelatedEntities, targetEntity, inverseProperty);
updateRelatedEntityInCollection(mc, relatedEntity, originalRelatedEntities, targetEntity, inverseProperty);
}
});
}
Expand Down Expand Up @@ -577,11 +577,21 @@ <h1 class="file-heading">File: ..\src\a55_mappingContext.js</h1>
}
}

function updateRelatedEntityInCollection(relatedEntity, relatedEntities, targetEntity, inverseProperty) {
function updateRelatedEntityInCollection(mc, relatedEntity, relatedEntities, targetEntity, inverseProperty) {
if (!relatedEntity) return;

// don&#x27;t update relatedCollection if preserveChanges &amp; relatedEntity has an fkChange.
if (relatedEntity.entityAspect.entityState === EntityState.Modified
&amp;&amp; mc.mergeOptions.mergeStrategy === MergeStrategy.PreserveChanges) {
var origValues = relatedEntity.entityAspect.originalValues;
var fkWasModified = inverseProperty.relatedDataProperties.some(function(dp) {
return origValues[dp.name] != undefined;
});
if (fkWasModified) return;
}
// check if the related entity is already hooked up
var thisEntity = relatedEntity.getProperty(inverseProperty.name);

if (thisEntity !== targetEntity) {
// if not - hook it up.
relatedEntities.push(relatedEntity);
Expand Down
16 changes: 13 additions & 3 deletions src/a55_mappingContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ var MappingContext = (function () {
if (typeof relatedEntity === 'function') {
mc.deferredFns.push(function () {
relatedEntity = relatedEntity();
updateRelatedEntityInCollection(relatedEntity, originalRelatedEntities, targetEntity, inverseProperty);
updateRelatedEntityInCollection(mc, relatedEntity, originalRelatedEntities, targetEntity, inverseProperty);
});
} else {
updateRelatedEntityInCollection(relatedEntity, originalRelatedEntities, targetEntity, inverseProperty);
updateRelatedEntityInCollection(mc, relatedEntity, originalRelatedEntities, targetEntity, inverseProperty);
}
});
}
Expand Down Expand Up @@ -370,11 +370,21 @@ var MappingContext = (function () {
}
}

function updateRelatedEntityInCollection(relatedEntity, relatedEntities, targetEntity, inverseProperty) {
function updateRelatedEntityInCollection(mc, relatedEntity, relatedEntities, targetEntity, inverseProperty) {
if (!relatedEntity) return;

// don't update relatedCollection if preserveChanges & relatedEntity has an fkChange.
if (relatedEntity.entityAspect.entityState === EntityState.Modified
&& mc.mergeOptions.mergeStrategy === MergeStrategy.PreserveChanges) {
var origValues = relatedEntity.entityAspect.originalValues;
var fkWasModified = inverseProperty.relatedDataProperties.some(function(dp) {
return origValues[dp.name] != undefined;
});
if (fkWasModified) return;
}
// check if the related entity is already hooked up
var thisEntity = relatedEntity.getProperty(inverseProperty.name);

if (thisEntity !== targetEntity) {
// if not - hook it up.
relatedEntities.push(relatedEntity);
Expand Down

0 comments on commit 4352e05

Please sign in to comment.