geddy / model

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

model.first(undefined,...) will return a data object?? #219

Closed yuchienho closed 10 years ago

yuchienho commented 10 years ago

geddy.model.User.first(undefined, function (err, user) { if (err) { throw err; } if (user) { console.log('find'); } }

get return "find", the user is the first item in my db.

geddy.model.User.first({id: undefined}, function (err, user) { if (err) { throw err; } if (user) { console.log('find'); } }

get no return, the user is null.

is this a bug?

mde commented 10 years ago

I don't think this is a bug. In the first case, you're not passing any sort of filter, so it returns the first result it can find in the DB. In the second case, you're explicitly trying to match the "id" property against the undefined non-value. This is the result I'd expect.