tommybananas/finale

Sorting ignored when obtaining hasMany relationship models

kevboutin opened this issue · 0 comments

When I have the following setup:

const Group = database.define('groups', {
    name: Sequelize.STRING,
    status: Sequelize.INTEGER,
    userId: {
        type: Sequelize.INTEGER,
        references: {
            model: 'users',
            key: 'id'
        }
    }
});

const User = database.define('users', {
    type: Sequelize.INTEGER,
    name: Sequelize.STRING
});

// Ensure one to many relationships are set-up.
Group.hasMany(User);

finale.resource({
    model: Group,
    endpoints: ['/groups', '/groups/:id'],
    associations: true
});

finale.resource({
    model: User,
    actions: ['list', 'read', 'update'],
    endpoints: ['/users', '/users/:id'],
    sort: {
        default: 'name'
    }
});

If I use a GET to /users, the sorting works as expected and the ORDER BY is seen in the SQL output to the logs. However, if I use a GET to /groups the users array will be sorted by the Id and not using the default sort given.

Please offer suggestions for work-around or to fork and fix.

Thanks!