When I have Associations relation I can do:
const results = await categoryModel.findAll({
include: [
{
model: moviesModel,
},
]}
And I will get the results like:
{ category_id: 1, name: "action" movies: [list of movies in the category] }
Is there I can get the same type of result without the categoryModel to query on? To query directly the movies model and get the results like so? so they will be grouped based on the category ID that they have?
Sequelize is not about complex aggregation queries, it's just for CRUD with associations like any other ORM library.
You can only reduce attributes you want to get from the category model indicating the attributes option like this:
const results = await categoryModel.findAll({
attributes: ['category_id'],
include: [
{
model: moviesModel,
},
]}