0

I have the following code

    Locations.findAll({
    attributes: ['id', 'location_name'],
    include: [{
        model: Somemodel,
        attributes: ['hierarchy_name']
       }]
    })

This will provide an output like this:

    id: 1
    location_name: "City"
    parent_id: 0
    hierarchy: 1
    location_hierarchy: {hierarchy_name: "Division"}

Is there any way that i can get the hierarchy_name without nesting the output with sequelize? Like this:

    id: 1
    location_name: "City"
    parent_id: 0
    hierarchy: 1
    hierarchy_name: "Division"

I know that i can destructure the data before sending it to client and i will get the format i want. But i want to know if this can be done directly from sequelize.

Rakib Uddin
  • 880
  • 1
  • 6
  • 17

1 Answers1

0

If you are expecting a massive dataset that you just want to display, without manipulation then you need to set an option raw to true.

Please refer the following question -

Setting all queries to raw = true sequelize

I hope it helps!

Soham Lawar
  • 1,165
  • 1
  • 12
  • 20