loopback icon indicating copy to clipboard operation
loopback copied to clipboard

find, findOne different empty result

Open evinw opened this issue 10 years ago • 5 comments

Object.findOne({ where: { and: [{user_id: user_id}] }, function(err, object){ console.log(object) // undefined }); Object.find({ where: { and: [{user_id: user_id}] }, function(err, object){ console.log(object) // [] }); findOne = no results returns 'undefined' // This is easy to check for for example ... if(typeof object !== 'undefined'){} but... find on no results returns empty array [] or nothing.

evinw avatar Jan 11 '16 23:01 evinw

Hi @evinw,

Could you please provide a sample repo using our loopback-sandbox to reproduce the issue?

Thanks!

Amir-61 avatar Jan 12 '16 01:01 Amir-61

@evinw

Do you still have the same issue? If so could you please provide a sample repo to reproduce the issue? Otherwise if it works, please let us know, so we can close this ticket.

Thanks a lot!

Amir-61 avatar Jan 26 '16 19:01 Amir-61

Closing this issue due to inactivity; please feel free to comment if you still have the same issue.

Thanks!

Amir-61 avatar Jan 29 '16 18:01 Amir-61

@Amir-61 querying the find method with object id returns the object, but when querying with any other params returns an empty array : File model has : id, imgId and eventId

File.find({where: {eventId: eventId}},function(err,res){
            console.log("found Image " + res)
            cb(err,res);
        })

Any idea why?

Hadh avatar Aug 25 '17 13:08 Hadh

I found out why, in the mode definition JSON file ( for me File.json), I needed to add "strictObjectIDCoercion": true to the options array, now querying with any params works

Hadh avatar Aug 25 '17 13:08 Hadh