0

I'm requesting the blueprint route User.findOne in SailsJs on the basis of user Id but it itself is calling User.update. Also, I just experienced a new thing that on sending multiple parameters to findOne, it updates the record on the basis of any single matched parameter. On the other hand, If i do create a controller named user.findOne and call the same route via controller, it works perfectly fine.

Is that the right behavior by SailsJs or I'm doing some mistake anywhere?

Adil
  • 21,278
  • 7
  • 27
  • 54
  • i have developed many project using SailsJs framework but i did not face any issue like you describe here. `User.findOne` only fetch record as par our query parameters. – Yogesh Patel Dec 07 '16 at 08:39
  • @YogeshPatel Yeah this seems to be completely unusual and strange. I'm not getting any mistake/loop hole at my end, that's why posted here with a hope that probably someone more expert would be able to identify the issue. – Adil Dec 07 '16 at 08:56
  • 1
    you can ask in sails gitter. There are many exports of SailsJs. – Yogesh Patel Dec 07 '16 at 13:23

1 Answers1

1

I have the same issue, still wondering why is this happening, I even tried creating an update function in my controller with some sample code but when I try hitting findOne from postman, it redirects me to my created update function. Waiting for an answer on this serious issue.

However I found a solution by trying something like this (i.e. creating custom findOne function in the controller) and it worked:

findOne : function (req,res){
    var myReq = req.params.all();
    console.log(myReq);
    User.findOne(myReq, function UserFound(err, user){
        if (err) return res.negotiate("User not found!");

        else{
            console.log("I am getting here");
            console.log(user);
            return res.status(200).send(user);
        }
    })
}
Adil
  • 21,278
  • 7
  • 27
  • 54