"findOne" doesn't search by "id" field
Closed this issue · 3 comments
I can find object by:
Post.find params.id, (err, post) =>
But I cannot find object by:
Post.findOne where: {id: params.id}, (err, post) =>
This is because this method is not designed for finding by id. Use find
instead, or specify correct mongodb ObjectID in findOne where param.
On Wed, Mar 27, 2013 at 8:26 PM, bioform notifications@github.com wrote:
I can find object by:
Post.find params.id, (err, post) =>
But I cannot find object by:
Post.findOne where: {id: params.id}, (err, post) =>
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/9
.
I work via ORM and it will be better to have the same syntax for it.
It is pretty strange if all my objects have "id" field, but I cannot find by this field easy way.
"findOne" can be used as:
Post.findOne({where: {id: params.id, deleted: false}}, cb)
or
Post.findOne({where: {id: params.id, user_id: req.user_id}}, cb)
Instead of using "find" and filtering objects on app level
It works now. Check version from master branch.
On Wed, Mar 27, 2013 at 9:44 PM, bioform notifications@github.com wrote:
I work via ORM and it will be better to have the same syntax for it.
It is pretty strange if all my objects have "id" field, but I cannot find
by this field easy way.
"findOne" can be used as:Post.findOne({where: {id: params.id, deleted: false}}, cb)
or
Post.findOne({where: {id: params.id, user_id: req.user_id}}, cb)
Instead of using "find" and filtering objects on app level
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/9#issuecomment-15539638
.
Thanks,
Anatoliy Chakkaev