0

I want to do inner join using sequelize ORM and it is working fine. But here it is returning in a nested object. How can we convert into a single object?

const caseProtaluserList = await models.Cases.findAll({include: [
    {
        model: models.Merchants, 
        attributes: ['name']
    }
]

output

{
    "case_Id": "1",
    "merchantId": 1,
    "primary_Email": "addad",
    "description": "dadad",
    "status": "dada",
    "createdAt": "2020-02-05T09:29:20.000Z",
    "updatedAt": "2020-02-05T09:29:20.000Z",
    "Merchant": {
        "name": "Waterstone Brands"
    }
}
Naor Levi
  • 1,713
  • 1
  • 13
  • 27
faruqneo
  • 1
  • 1
  • i want in this format ``` "case_Id": "1", "merchantId": 1, "primary_Email": "addad", "description": "dadad", "status": "dada", "createdAt": "2020-02-05T09:29:20.000Z", "updatedAt": "2020-02-05T09:29:20.000Z", "Merchant": "Waterstone Brands" ``` – faruqneo Feb 06 '20 at 05:57
  • I don't think there's such an option. Look the `includeOptions` interface of sequelize: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/sequelize/index.d.ts#L3252. You could just manipulate the object after the query. – Naor Levi Feb 06 '20 at 08:59
  • Try using raw:true to get flatten result. This might help you https://stackoverflow.com/questions/41502699/return-flat-object-from-sequelize-with-association – Vipul Patil Feb 06 '20 at 09:27

0 Answers0