• 카테고리

    질문 & 답변
  • 세부 분야

    풀스택

  • 해결 여부

    해결됨

Cannot read property 'belongsToMany' of undefined

20.07.27 10:25 작성 조회수 410

0

db.Hashtag 가 왜 undefined로 나올까요 ㅠㅜ

에러메세지 입니다.

TypeError: Cannot read property 'belongsToMany' of undefined

    at Function.Hashtag.associate (D:\005_Study\React\react-nodebird\prepare\back\models\hashtag.js:12:16)

    at D:\005_Study\React\react-nodebird\prepare\back\models\index.js:19:19

    at Array.forEach (<anonymous>)

    at Object.<anonymous> (D:\005_Study\React\react-nodebird\prepare\back\models\index.js:17:17)

    at Module._compile (internal/modules/cjs/loader.js:1138:30)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)

    at Module.load (internal/modules/cjs/loader.js:986:32)

    at Function.Module._load (internal/modules/cjs/loader.js:879:14)

    at Module.require (internal/modules/cjs/loader.js:1026:19)

    at require (internal/modules/cjs/helpers.js:72:18)

hashtag.js입니다.

module.exports = (sequelizeDataTypes=> {
  const Hashtag = sequelize.define('Hashtag', {
    name: {
      type: DataTypes.STRING(20),
      allowNull: false,
    },
  }, {
    charset: 'utf8mb4'// 이모티콘 넣으려면 mb4 넣어줘야한다.
    collate: 'utf8mb4_general_cli'// 한글 및 이모티콘 저장
  });
  Hashtag.associate = (db=> {
    db.Hashtag.belongsToMany(db.Post, { through: 'PostHashTag' });
  };
  return Hashtag;
}

답변 3

·

답변을 작성해보세요.

1

아 맞네요 ㅠㅜ  Hashtag HashTag...

1

index.js 보여주세요.

1

감자도리님의 프로필

감자도리

2020.07.27

조심스럽게 index.js 파일 오타 의심해봅니다 ㅋ