Description
Using orderBy constraint on nested relations does not fulfil the order criteria.
This seems to be affecting the following relationships:
Steps to reproduce
- Create a model with at least one many-to-many relationship.
static fields() {
return {
id: this.attr(null),
roles: this.belongsToMany(Role, RoleUser, 'user_id', 'role_id')
}
}
- Supply some data.
User.create({
data: {
id: 1,
roles: [
{ id: 1 },
{ id: 3 },
{ id: 2 }
]
}
})
- Retrieve the data with the relation constraint.
const user = User.query().with('roles', (query) => { query.orderBy('id') }).find(1)
Expected behaviour
The user roles should be in ascending order by id.
{
id: 1,
roles: [
{ id: 1 }, // Role
{ id: 2 }, // Role
{ id: 3 } // Role
]
} // User
The order is actually symmetrical to the order the records, pivots et all, are created.
{
id: 1,
roles: [
{ id: 1 }, // Role
{ id: 3 }, // Role
{ id: 2 } // Role
]
} // User
Demo
An example of a Many To Many implementation can be found here.
Versions
- Vuex ORM: 0.35.2
- All previous versions since
orderBy feat was introduced.
Description
Using
orderByconstraint on nested relations does not fulfil the order criteria.This seems to be affecting the following relationships:
Steps to reproduce
Expected behaviour
The user roles should be in ascending order by
id.The order is actually symmetrical to the order the records, pivots et all, are created.
Demo
An example of a Many To Many implementation can be found here.
Versions
orderByfeat was introduced.