Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorting ignored with hasMany relationships #235

Open
kevboutin opened this issue Oct 4, 2018 · 0 comments
Open

Sorting ignored with hasMany relationships #235

kevboutin opened this issue Oct 4, 2018 · 0 comments

Comments

@kevboutin
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant