dresende / node-orm2

Object Relational Mapping
http://github.com/dresende/node-orm2
MIT License
3.07k stars 379 forks source link

[request] findById() support #581

Open syzer opened 9 years ago

syzer commented 9 years ago

Right now i'm running query like this:

Parasite.find({ParasiteID: req.params.id}, function (err, parasitesData) {

But model Parasite has already defined That ParasiteID is its primary key so i would like to run such a query by:

Parasite.findById(req.params.id, function (err, parasitesData) {

that would allow abstracting away process of creating controllers

jacobp100 commented 9 years ago

Parasite.get(req.params.id...)

syzer commented 9 years ago

:) +1 ready to close so i can get

Parasite.findById = Parasite.get

One more question: I was trying to get general method to get primary key name of Parasite:

Parasite.keys[0]

or is there any general method, like getUUID()?

jacobp100 commented 9 years ago

If I understand correctly, you want to get the primary key column name. In which case, I think you should just be using id for the id field---it's much more predictable.

syzer commented 9 years ago

In a perfect world.... but I do not own the Db. Cannot use id as key name. I used keys[0].. since i could not find API method for it.

jacobp100 commented 9 years ago

You can always just set keys[0] to whatever you want. Use Object.defineProperty if you're going to do it though!