node-orm2 icon indicating copy to clipboard operation
node-orm2 copied to clipboard

How do you implement the find_or_create function?

Open ronald2wing opened this issue 9 years ago • 1 comments

I find it difficult to implement this functionality. Has anyone done it before?

ronald2wing avatar Nov 30 '16 23:11 ronald2wing

    Chat.count({ id: chatId }, function(err, count) {
      if (count === 0) {
        Chat.create({ id: chatId }, (err) => {
          console.log(err);
        });
      }
    });

Right now I am combining count and create to create a similar method. Is there a better way to do this?

ronald2wing avatar Dec 01 '16 04:12 ronald2wing