sequelize-typescript icon indicating copy to clipboard operation
sequelize-typescript copied to clipboard

get the child's child attributes its parent

Open DigiGroundJohn opened this issue 7 years ago • 2 comments

Hi,

The below function is working, getting all the details of the users and its association. Can we get the child's child attributes in the children? Is there any way I can fetch the count of starsST in each story and "behaviourName" attribute in the story model.

I already tried sequelize hierarchy. I am looking forward to your suggestion. Thanks

const teamMemberDetails = await this.userModel.findAll({ hierarchy: true, attributes: ['id','firstName','lastName', 'fullName' , 'dateOfBirth', [Sequelize.col("Office.officeName"), "Location"], 'phoneNumber',

      ],
      include:[
            {
            model:this.officeModel, as:'Office',
            attributes: ['officeName']
          },
          {
            model:this.storiesModel, as: 'storiesTM',
            hierarchy: true,
            attributes: ['creationOn', 
       Sequelize.col('child.lastName')), 'StoryFor'],
          ], 
              include:[{
                  model:this.behavioursModel, as: 'behaviour',
                  hierarchy: true,
                attributes: ['behaviourName'],
              },{
                model:this.userModel, as :'child',
                attributes: ['firstName','lastName','fullName',],
              },
              {
                model:this.starStoriesModel, as :'starsST',
                attributes: ['id'],
              }
            ]
          },
          {
            model:this.teamsModel, as: 'teamMembers',
          attributes: ['childId'],
              include:[{
                  model:this.userModel, as :'child',
                  attributes: ['firstName', 'lastName','fullName','startDate'],
                }]
          }
        ],
    where :{id:userId},
  })    
  return teamMemberDetails; 

DigiGroundJohn avatar Nov 08 '19 02:11 DigiGroundJohn

can i see your model class and your database settings ?? I need this hierarchy too.

FauziFadhi avatar Nov 09 '19 05:11 FauziFadhi

Closing this due to inactivity

RobinBuschmann avatar Dec 18 '19 18:12 RobinBuschmann