小编Per*_*öjd的帖子

使用 sequelize 防止将连接表数据添加到 json

我有以下与续集相关的模型。

Event hasMany Characters through characters_attending_boss
Boss hasMany Characters through characters_attending_boss
Characters hasMany Event through characters_attending_boss
Characters hasMany Boss through characters_attending_boss
Run Code Online (Sandbox Code Playgroud)

这些表已成功连接,我可以从中检索数据。但是当我检索 JSON 结果时,直通模型的名称被添加到每个对象中,如下所示:

{
   id: 1
   title: "title"
   -confirmed_for: [ //Alias for Event -> Character
       -{
          id: 2
          character_name: "name"
          -confirmed_for_boss: [ // Alias for Boss -> Character
              -{
                   id: 9
                   name: "name"
                   -character_attending_event: { // name of through-model
                         event_id: 1
                         char_id: 2
                   }
               }
    ]
    -character_attending_boss: { // name of through-model
          event_id: 1
          char_id: 2
    } …
Run Code Online (Sandbox Code Playgroud)

json has-many express sequelize.js

4
推荐指数
1
解决办法
785
查看次数

标签 统计

express ×1

has-many ×1

json ×1

sequelize.js ×1