foam-framework / foam

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

Adding 'orderBy' causing incorrect query results to be returned. #139

Open bshepherdson opened 10 years ago

bshepherdson commented 10 years ago

From mr.g.e.a...@gmail.com on December 27, 2013 13:49:28

Steps will reproduce the problem:

  1. Run this sample code:
var Direction = FOAM({
  model_: 'Model',
  name: 'Direction',
  ids: ['directionID'],
  properties: [
    { name: 'directionID', model_: 'IntegerProperty'},
    { name: 'directionCode', model_: 'IntegerProperty'},
    { name: 'directionGroup', model_: 'IntegerProperty'},
  ]
});

var directions = MDAO.create({model: Direction})
  .addIndex(Direction.DIRECTION_CODE)
  .addIndex(Direction.DIRECTION_GROUP);

// Initial Data
directions.put(Direction.create({directionID: 1, directionCode: 1, directionGroup: 100}));
directions.put(Direction.create({directionID: 2, directionCode: 1, directionGroup: 100}));
directions.put(Direction.create({directionID: 3, directionCode: -1, directionGroup: 900}));
directions.put(Direction.create({directionID: 4, directionCode: -1, directionGroup: 900}));
directions.put(Direction.create({directionID: 5, directionCode: 2, directionGroup: 500}));

var selection =  directions
  .where(IN(Direction.DIRECTION_GROUP, [900]))
  .where(EQ(Direction.DIRECTION_CODE, -1))
  .where(EQ(Direction.DIRECTION_ID, 3));

selection
  .select(function(data) { console.log("[plain] ID: " + data.directionID); });

selection
  .orderBy(Direction.DIRECTION_GROUP)
  .select(function(data) { console.log("[ordered] ID: " + data.directionID); });

Expected output:

[plain] ID: 3
[ordered] ID: 3

Actual output:

[plain] ID: 3
[ordered] ID: 3
[ordered] ID: 4

Tested on:

Google Chrome Version 31.0.1650.63 m

Original issue: http://code.google.com/p/foam-framework/issues/detail?id=139

bshepherdson commented 10 years ago

From k...@chromium.org on December 28, 2013 12:30:45

Thanks for the bug report. I'll have a look. This might be related/the-same-as Issue#79 . I plan on rewriting the offending section of code.

Status: Accepted
Owner: k...@chromium.org
Labels: -Priority-Medium Priority-High Component-Persistence

bshepherdson commented 8 years ago

Assigning to myself to try to reproduce today.