Thursday 4 May 2017

In sequelize.js, is it possible to un-nest the results of a query with nested includes?

I want to be able to nest my includes in a query, but I wanted the results to be un-nested.

For example:

db.a.findAll({
    where: {id: id},
    include: [
        { model: db.b, include: [
            { model: db.c, include: [
                { model: db.e }
            ]}
        ]}
    ]
})
...

returns something like this:

[
    a: {
        ...
        b: {
            ...
            c: {
                ...
                d: {
                    ...
                }
            }
        }
    }
]

but I want this:

[
    a: {
        ...
        b: {
            ...
        }
        c: {
            ...
        }
        d: {
            ...
        }
    }
]

Is this possible without refactoring the models/tables?



via gurs1kh

No comments:

Post a Comment