bitovi / querystring-parser

MIT License
8 stars 5 forks source link

Deep Nested Filters for Sequelize #51

Closed Nicopiwi closed 6 months ago

Nicopiwi commented 1 year ago

In the @bitovi/sequelize-querystring-parser package apparently I cannot filter by a deep nested attribute. Using the IBM Style query include=route&filter=equals(route.name, 'hello'), I'm getting the following object:

{
    orm: 'sequelize', 
    data: {
        where: {
            route.name: {Symbol(eq): 'hello'}
        },
        include: [{association: 'route', include: Array(0)}]}, 
    },

    errors: Array(0)
}

When I should get the following Object:

{
    orm: 'sequelize', 
    data: {
        include: [
            {
                association: 'route',
                where: {
                    name: {Symbol(eq): 'hello'}
                }, 
                include: Array(0)
            }
        ]
    }, 
    errors: Array(0)
}
roy-coder commented 6 months ago

@Nicopiwi Thank you for posting the question here and apologies for the time it took us to respond. There are multiple ways to represent your query in Sequelize. While in your example it looks nicer to add the filtering under the association, moving the filters to the top-level allows more complex queries, such as having OR between different filters applied on different associations. To read more about the options available in Sequelize: https://sequelize.org/docs/v6/advanced-association-concepts/eager-loading/#complex-where-clauses-at-the-top-level. Feel free to reach out if you have further questions.