sequelize “findbyid” is not a function but apparently “findAll” is

后端 未结 3 729
别那么骄傲
别那么骄傲 2021-02-06 20:51

I am getting a very strange problem with sequelize, When I try to call the function findAll it works fine (same for create and destroy), but when I try to call function \"findBy

相关标签:
3条回答
  • 2021-02-06 21:36

    Directly pass value.

    Question.findByPk(question_id).then(question => {
                return res.status(200).json({
                    question: question
               });
    }).catch(err => {
         console.log(err);
    });
    
    0 讨论(0)
  • 2021-02-06 21:45

    the team of sequelize was deleting this function and replced it by a new function is

    findByPk

    like this

    // search for known ids
    Project.findByPk(123).then(project => {
      // project will be an instance of Project and stores the content of the table entry
      // with id 123. if such an entry is not defined you will get null
    })
    
    0 讨论(0)
  • 2021-02-06 21:52

    With Sequelize v5, findById() was replaced by findByPk(). Replace findById using findByPk and everything should work fine. You can find query doc here

    0 讨论(0)
提交回复
热议问题