Prevent junction-table data from being added to json with sequelize
Asked Answered
C

2

5

I've got the following models associated with 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

These tables are successfully joined and I can retrieve data from them. But when I retrieve the JSON-results the name of the through model gets added to each object, like this:

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

So I'm looking for a way to hide these "character_attending_boss" segments if possible, preferably without altering the results post-fetch.

Is this possible?

Contributory answered 14/10, 2014 at 14:10 Comment(0)
S
7

Same issue is solved here: https://github.com/sequelize/sequelize/issues/2541

For me adding through: {attributes: []} to include block works well on Sequelize 2.0

Shadbush answered 19/12, 2014 at 15:30 Comment(0)
P
1

Pass { joinTableAttributes: [] } to the query.

Palpitation answered 9/11, 2014 at 15:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.