2017-10-04 124 views
0

我想使用sequelize & nodeJS在我們的postgresql數據庫上進行查詢。Sequelize嵌套數據結構

除了模型深層嵌套關係的結構之外,這一切都工作正常。

我的例子:

{ 
     model: this.Parent, 
     as: 'Parent', 
     include: [ 
     { 
      model: this.Child, 
      as: 'child', 
      include: [ 
      { 
       model: this.nestedChild, 
       as: 'nestedChild', 
      }, 
      ], 
     }, 
     ], 
    }, 

爲孩子和nestedChild在「包括」對象返回的數據,問題是,nestedChild不再是「關係」的對象的孩子,而不是它的其中一個參數。 例如:

data: [proper array of Parent elements with defined 'child' relationship in 'relationships' object], 
included: [ 
    { 
     attributes: { 
      nested-child: { 
      (here are properties for my nestedChild) 
      } 
     }, 
    relationships: <------ this is missing, and should include my nestedChild 
    } 
] 

回答

0

原來,嵌套關係查詢很好。這是那個步驟之後的JSON序列化程序,它沒有定義正確的結構,因此一旦將響應發送到前端,它就會丟失。