Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you implement the find_or_create function? #757

Open
ronald2wing opened this issue Nov 30, 2016 · 1 comment
Open

How do you implement the find_or_create function? #757

ronald2wing opened this issue Nov 30, 2016 · 1 comment

Comments

@ronald2wing
Copy link

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

@ronald2wing
Copy link
Author

    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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant