You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you can fit a quick nice feature into your next release, I would like a findOne function in addition to the find(...).limit(1) functionality. This would make integration with user validation/authentication a little cleaner IMO.
Thank you, I'm very appreciative of this library. There are not very many good ORM libraries for MySQL.
There is a Model.all so probably I'll create a Model.one. In your case it shouldn't be possible because you should have at most 1 result or your authentication might have a breach :) I'll commit it soon and release it this week.
Haha, yes, having more than one result would be indicative of an issue. More along the lines of what I hoped to solve with this idea is eliminating the var user = users[0] from the following snippet:
// findOne or one, syntax is obviously up to you. // I'm familiar with the findOne vs. find from the Mongoose API.User.[findOne|one]({username: username},function(err,user){// no need to access the first element.
...
Will the alias Model.one() cover this concept? From my understanding (which may very well be incorrect), even if it is a limit of 1 it will still return an array, albeit with a length of 1.
Activity
dresende commentedon May 5, 2013
There is a
Model.allso probably I'll create aModel.one. In your case it shouldn't be possible because you should have at most 1 result or your authentication might have a breach :) I'll commit it soon and release it this week.Adds Model.one() as an alias for Model.all().limit(1) (#148)
jogly commentedon May 6, 2013
Haha, yes, having more than one result would be indicative of an issue. More along the lines of what I hoped to solve with this idea is eliminating the
var user = users[0]from the following snippet:with
Will the alias Model.one() cover this concept? From my understanding (which may very well be incorrect), even if it is a limit of 1 it will still return an array, albeit with a length of 1.
dxg commentedon May 6, 2013
Could also call it 'first()'.
i too would find it useful if it just returned the item rather than an array.
dresende commentedon May 6, 2013
Yes, the simple implementation I added will return an
Arrayof results. I'll have to change it.Changes Model.one() to return only one instance (or null) instead of …
dresende commentedon May 6, 2013
For now it forces a callback, you can't do this:
For now, only: