Skip to content

Commit

Permalink
Fix bug with datastore when two references are on the same entity
Browse files Browse the repository at this point in the history
  • Loading branch information
fzaninotto committed Sep 8, 2015
1 parent f358afe commit 637128e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 31 deletions.
33 changes: 11 additions & 22 deletions src/javascripts/ng-admin/Crud/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,15 @@ function routing($stateProvider) {
}],
referencedEntries: ['dataStore', 'view', 'nonOptimizedReferencedData', 'optimizedReferencedData', function (dataStore, view, nonOptimizedReferencedData, optimizedReferencedData) {
var references = view.getReferences(),
referencedData = angular.extend(nonOptimizedReferencedData, optimizedReferencedData),
referencedEntries;
referencedData = angular.extend(nonOptimizedReferencedData, optimizedReferencedData);

for (var name in referencedData) {
referencedEntries = Entry.createArrayFromRest(
Entry.createArrayFromRest(
referencedData[name],
[references[name].targetField()],
references[name].targetEntity().name(),
references[name].targetEntity().identifier().name()
);
referencedEntries.map(entry => dataStore.addEntry(references[name].targetEntity().uniqueId + '_values', entry));
).map(entry => dataStore.addEntry(references[name].targetEntity().uniqueId + '_values', entry));
}

return true;
Expand Down Expand Up @@ -180,17 +178,15 @@ function routing($stateProvider) {
}],
referencedEntries: ['dataStore', 'view', 'nonOptimizedReferencedData', 'optimizedReferencedData', function (dataStore, view, nonOptimizedReferencedData, optimizedReferencedData) {
var references = view.getReferences(),
referencedData = angular.extend(nonOptimizedReferencedData, optimizedReferencedData),
referencedEntries;
referencedData = angular.extend(nonOptimizedReferencedData, optimizedReferencedData);

for (var name in referencedData) {
referencedEntries = Entry.createArrayFromRest(
Entry.createArrayFromRest(
referencedData[name],
[references[name].targetField()],
references[name].targetEntity().name(),
references[name].targetEntity().identifier().name()
);
referencedEntries.map(entry => dataStore.addEntry(references[name].targetEntity().uniqueId + '_values', entry))
).map(entry => dataStore.addEntry(references[name].targetEntity().uniqueId + '_values', entry))
}

return true;
Expand All @@ -211,17 +207,12 @@ function routing($stateProvider) {
referencedList = referencedLists[i];
referencedListEntries = referencedListData[i];

referencedListEntries = Entry.createArrayFromRest(
Entry.createArrayFromRest(
referencedListEntries,
referencedList.targetFields(),
referencedList.targetEntity().name(),
referencedList.targetEntity().identifier().name()
);

dataStore.setEntries(
referencedList.targetEntity().uniqueId + '_list',
referencedListEntries
);
).map(entry => dataStore.addEntry(referencedList.targetEntity().uniqueId + '_list', entry));
}
}],
entryWithReferences: ['dataStore', 'view', 'entry', 'referencedEntries', function(dataStore, view, entry, referencedEntries) {
Expand Down Expand Up @@ -314,17 +305,15 @@ function routing($stateProvider) {
}],
referencedEntries: ['dataStore', 'view', 'nonOptimizedReferencedData', 'optimizedReferencedData', function (dataStore, view, nonOptimizedReferencedData, optimizedReferencedData) {
var references = view.getReferences(),
referencedData = angular.extend(nonOptimizedReferencedData, optimizedReferencedData),
referencedEntries;
referencedData = angular.extend(nonOptimizedReferencedData, optimizedReferencedData);

for (var name in referencedData) {
referencedEntries = Entry.createArrayFromRest(
Entry.createArrayFromRest(
referencedData[name],
[references[name].targetField()],
references[name].targetEntity().name(),
references[name].targetEntity().identifier().name()
);
referencedEntries.map(entry => dataStore.addEntry(references[name].targetEntity().uniqueId + '_values', entry))
).map(entry => dataStore.addEntry(references[name].targetEntity().uniqueId + '_values', entry))
}

return true;
Expand Down
12 changes: 3 additions & 9 deletions src/javascripts/ng-admin/Main/config/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,15 @@ function routing($stateProvider, $urlRouterProvider) {
optimizedReferencedData = optimizedReference;

var references = collection.getReferences(),
referencedData = angular.extend(nonOptimizedReferencedData, optimizedReferencedData),
referencedEntries;
referencedData = angular.extend(nonOptimizedReferencedData, optimizedReferencedData);

for (var name in referencedData) {
referencedEntries = Entry.createArrayFromRest(
Entry.createArrayFromRest(
referencedData[name],
[references[name].targetField()],
references[name].targetEntity().name(),
references[name].targetEntity().identifier().name()
);

dataStore.setEntries(
references[name].targetEntity().uniqueId + '_values',
referencedEntries
);
).map(entry => dataStore.addEntry(references[name].targetEntity().uniqueId + '_values', entry));
}
})
.then(() => {
Expand Down

0 comments on commit 637128e

Please sign in to comment.