geddy / model

Datastore-agnostic ORM in JavaScript
265 stars 55 forks source link

Date range call with id query always returns empty set #232

Open deepcover96 opened 9 years ago

deepcover96 commented 9 years ago

this works: model.Person.all({createdAt: {lt: ltVal, gt: gtVal}}, ...

this also works: model.Person.all({id: ids, createdAt: {lt: ltVal}}, ...

this returns an empty set, even though it should return rows model.Person.all({id: ids, createdAt: {lt: ltVal, gt: gtVal}}}, ...

seems like using a date range with an id will return an empty array every time I tested with 13.0.4

here's what I see in the SQL, here's a good one model.Person.all({id: ids, createdAt: {gte: gte}}, ...

SELECT FROM persons ... WHERE (persons."created_at" >= '2014-10-15T18:44:09.119' AND persons."id" IN ('723C3381-6ABB-5C37-4F99-B1AFF280940A', '14833DAB-D083-67D4-5D77-880A6BD93227', '05FF3F6B-B637-5D85-8533-B766ECC9AA4B'));

and now a problematic one model.Person.all({id: ids, createdAt: {lt: ltVal, gt: gtVal}}}, ...

SELECT FROM persons ... WHERE (persons."created_at" >= '2014-10-16T07:00:00.000' AND persons."created_at" <= '2014-10-17T06:59:59.999' AND persons."id" >= NULL AND persons."id" <= NULL);
danfinlay commented 9 years ago

Id >= null, eh? That sure looks buggy to me.

mde commented 9 years ago

I can't repro this. I added a test for it, "test all, using id-range, and less-than-or-equal and greater-than-or-equal with createdAt":

https://github.com/geddy/model/commit/409ccc0f0c9884562f10b87b6c6319af89861901

The tests pass in all the supported adapters:

https://travis-ci.org/geddy/model/builds/38560682

Here's the generated SQL for the auto-increment ID tests (UUID string yields the same results):

SELECT "people"."id" AS "Person#id", "people"."created_at" AT TIME ZONE 'UTC' AS "Person#createdAt", "people"."updated_at" AT TIME ZONE 'UTC' AS "Person#updatedAt", "people"."family_name" AS "Person#familyName", "people"."given_name" AS "Person#givenName", "people"."title" AS "Person#title", "people"."description" AS "Person#description", "people"."child_person_id" AS "Person#childPersonId", "people"."admin_event_id" AS "Person#adminEventId", "people"."owner_event_id" AS "Person#ownerEventId"
FROM people people
WHERE ("people"."id" IN (916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 930, 931, 932, 933, 934, 935) AND "people"."created_at" <= '2014-10-21T01:30:48.990' AND "people"."created_at" >= '2014-10-21T01:30:38.990');

Could you provide a bit more information? It sounds like you're using Geddy v13, which is Model v6.

deepcover96 commented 9 years ago

OK. Hmm. Only thing that I see different is that I'm using UUID strings as IDs and you're using integers.

I tried it with v0.12.12 (model 0.5.16) and 13.0.4 (model 6.0.1) with the same results. I'll go through it tomorrow to make sure that the problem is real and report back.