Skip to content

Sorting ignored with hasMany relationships #235

@kevboutin

Description

@kevboutin

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);

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

epilogue.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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions