hasMany로 연결된 테이블 include 에러

‍박소연·2023년 5월 10일
const admin = await Competition.create({
            admin_id, 
            admin_pw: password, 
            game_name: comp_data.game_name, 
            comp_name: comp_data.comp_name, 
            team_num: comp_data.team_num, 
            match: comp_data.match, 
            start_date: comp_data.start_date, 
            due_date: comp_data.due_date, 
            comp_date: comp_data.comp_date, 
            comp_detail: comp_data.comp_detail,

            Tournament: {
                layer_1: JSON.stringify(team_list['0']),
                final: JSON.stringify(team_list.final),
                winner: JSON.stringify(team_list.winner)
            },

            Teams: {
                team_name: JSON.stringify(team_list['0'])
            }
        }, {
            include: [{model: Tournament} ,{model: Team}]
        });

위 코드에서는 Teams 배열을 추가해서 Team 모델의 데이터를 저장할 수 있습니다. Team 모델을 include 옵션으로 추가할 때는 복수형(Teams)으로 작성해야 합니다.


그리고 include도 처음에는 이렇게 썼는데 따로 불러와야 된다고 한다...

include: [{model: Tournament, Team}]

그래서 Team 테이블에 계속 저장이 안된거니?

0개의 댓글