I am using Sequelize ORM for Postgres db. My tables and associations look like:
My associations:
Users.hasMany(Options, {
foreignKey: 'userId'
});
Options.belongsTo(User);
Users.hasMany(Finders, {
foreignKey: 'userId'
});
Finders.belongsTo(User);
How can I make a query using Sequelize to get Users data and associated data from tables Options and Finders in the same object (without nested objects)? The query result should be:
[
{
id: 1,
name: 'Mark',
option: 'opt1',
finder: 'films'
},
{
id: 1,
name: 'Mark',
option: 'opt2',
finder: 'films'
},
{
id: 2,
name: 'Lalo',
option: 'opt3',
finder: 'books'
},
]