The hasMany association should return a list of object, rights? I have a user record and a few connections records connected to it.
model connections:
userId: {
field: 'user_id',
type: DataTypes.STRING,
allowNull: false
}
model users:
(users as any).associate = function associate(models: any) {
models.users.hasMany(models.connections, {
as: 'connections',
foreignKey: 'user_id'
});
};
I include the connections model by adding it to the sequelize query params:
include: [{ model: context.app.service('connections').Model, as: 'connections' }],
The end result is that the connections property in the user response is a single object instead of an array of objects.
I logged the Sequelize’s query executions and tried directly in the DB the raw query that Sequelize does for this particular call and it returns a list of records, as it should. But when I query it through the API, it returns just a single object instead of an array.