【问题标题】:Prevent junction-table data from being added to json with sequelize使用 sequelize 防止连接表数据添加到 json
【发布时间】:2014-12-09 08:58:49
【问题描述】:

我有以下与 sequelize 相关的模型。

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”段,最好不要更改获取后的结果。

这可能吗?

【问题讨论】:

    标签: json express has-many sequelize.js


    【解决方案1】:

    同样的问题在这里解决了:https://github.com/sequelize/sequelize/issues/2541

    对我来说,添加 through: {attributes: []} 以包含块在 Sequelize 2.0 上效果很好

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2014-01-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-04
        • 2012-01-13
        • 2018-02-04
        • 1970-01-01
        • 2021-02-19
        相关资源
        最近更新 更多