使用sequelize防止将联结表数据添加到json

时间:2014-10-14 14:10:24

标签: json express has-many sequelize.js

我有以下与sequ​​elize相关的模型。

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

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

{
   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
    }
}

所以我正在寻找一种方法来隐藏这些“character_attending_boss”段,如果可能的话,最好不要在取回后改变结果。

这可能吗?

2 个答案:

答案 0 :(得分:4)

此处解决了同样的问题:https://github.com/sequelize/sequelize/issues/2541

对于我来说,添加through: {attributes: []}以包含块在Sequelize 2.0上运行良好

答案 1 :(得分:1)

{ joinTableAttributes: [] }传递给查询。

相关问题