Closed bshepherdson closed 10 years ago
From k...@chromium.org on December 12, 2013 14:34:10
You never specified a unique index. If you would like directionId to be the unique primary key, then either specify that by including ids: ['directionID'] or renaming the field to 'id'. As shown below:
var Direction = FOAM({ model: 'Model', name: 'Direction', ids: ['directionID'], properties: [ { name: 'directionID', model: 'IntegerProperty'}, { name: 'directionCode', model_: 'IntegerProperty'}, ] });
var Direction = FOAM({ model: 'Model', name: 'Direction', properties: [ { name: 'id', model: 'IntegerProperty'}, { name: 'directionCode', model_: 'IntegerProperty'}, ] });
Status: Invalid
Labels: Component-Persistence
From mr.g.e.a...@gmail.com on December 13, 2013 06:33:12
Neither suggestion resolves the issue demonstrated in the example provided.
From k...@chromium.org on December 13, 2013 07:35:03
Indeed, you're correct. I'll fix. Thx
Status: Accepted
From k...@chromium.org on December 13, 2013 07:36:22
This issue was closed by revision 7903a1a398ca .
Status: Fixed
From drmac...@gmail.com on December 12, 2013 16:16:17
The code: var Direction = FOAM({ model: 'Model', name: 'Direction', properties: [ { name: 'directionID', model: 'IntegerProperty'}, { name: 'directionCode', model_: 'IntegerProperty'}, ] });
var directions = MDAO.create({model: Direction}) .addIndex(Direction.DIRECTION_CODE);
// Initial Data directions.put(Direction.create({directionID: 1, directionCode: 1})); directions.put(Direction.create({directionID: 2, directionCode: 1})); directions.put(Direction.create({directionID: 3, directionCode: -1})); directions.put(Direction.create({directionID: 4, directionCode: -1})); directions.put(Direction.create({directionID: 5, directionCode: 2}));
// Update (re-put) Datum '4' with different 'directionCode'. directions.put(Direction.create({directionID: 4, directionCode: 2}));
directions.select(function(data) { console.log("[plain] ID: " + data.directionID + ", CODE: " + data.directionCode); }); directions.orderBy(Direction.DIRECTION_CODE).select(function(data) { console.log("[ordered] ID: " + data.directionID + ", CODE: " + data.directionCode); });
The output: [plain] ID: 1, CODE: 1 [plain] ID: 2, CODE: 1 [plain] ID: 3, CODE: -1 [plain] ID: 4, CODE: 2 [plain] ID: 5, CODE: 2 [ordered] ID: 3, CODE: -1 [ordered] ID: 4, CODE: -1 ** [ordered] ID: 1, CODE: 1 [ordered] ID: 2, CODE: 1 [ordered] ID: 4, CODE: 2 ** [ordered] ID: 5, CODE: 2
Original issue: http://code.google.com/p/foam-framework/issues/detail?id=131