PhilWaldmann / openrecord

Make ORMs great again!
https://openrecord.js.org
MIT License
486 stars 38 forks source link

Model.find() with empty argument has an unexpected return #90

Closed arthurfranca closed 5 years ago

arthurfranca commented 5 years ago

await Model.find(/*null or undefined*/) is returning the same as await Model.first()

So when one writes await Model.find(req.params.id) on Express with an empty id, it will inadvertently show or edit the wrong object.

Maybe it's best to return undefined, just like when finding by a primary key value absent from DB. Like if the query were select * from model where id is null limit 1.

PhilWaldmann commented 5 years ago

Wow, that totally got unnoticed for a while! Thanks for finding this bug. I'll fix it, give me a moment.

PhilWaldmann commented 5 years ago

fixed with version 2.8.5

Thanks @arthurfranca