Skip to content

How do you implement the find_or_create function? #757

Description

@ronald2wing

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

Activity

  1. ronald2wing commented on Dec 1, 2016

    @ronald2wing
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions