foam-framework / foam

Feature-Oriented Active Modeller
Apache License 2.0
787 stars 55 forks source link

Unique index not enforced when bean updated #131

Closed bshepherdson closed 10 years ago

bshepherdson commented 10 years ago

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

bshepherdson commented 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

bshepherdson commented 10 years ago

From mr.g.e.a...@gmail.com on December 13, 2013 06:33:12

Neither suggestion resolves the issue demonstrated in the example provided.

bshepherdson commented 10 years ago

From k...@chromium.org on December 13, 2013 07:35:03

Indeed, you're correct. I'll fix. Thx

Status: Accepted

bshepherdson commented 10 years ago

From k...@chromium.org on December 13, 2013 07:36:22

This issue was closed by revision 7903a1a398ca .

Status: Fixed