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

Many-to-many relations orderBy constraint does not resolve #571

Closed
cuebit opened this issue Feb 22, 2020 · 3 comments · Fixed by #586
Closed

Many-to-many relations orderBy constraint does not resolve #571

cuebit opened this issue Feb 22, 2020 · 3 comments · Fixed by #586
Assignees
Labels
bug Something isn't working resolved Issue have been resolved but not yet released

Comments

@cuebit
Copy link
Member

cuebit commented Feb 22, 2020

Description

Using orderBy constraint on nested relations does not fulfil the order criteria.

This seems to be affecting the following relationships:

Steps to reproduce

  1. 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')
   }
}
  1. Supply some data.
User.create({
  data: {
    id: 1,
    roles: [
      { id: 1 },
      { id: 3 },
      { id: 2 }
    ]
  }
})
  1. 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.
cuebit added a commit to cuebit/vuex-orm that referenced this issue Feb 22, 2020
@kiaking
Copy link
Member

kiaking commented Mar 3, 2020

Thanks for finding this out! Is the fix ready...?

@kiaking kiaking added the bug Something isn't working label Mar 3, 2020
@kiaking kiaking added this to the v1.0.0 milestone Mar 3, 2020
@cuebit
Copy link
Member Author

cuebit commented Mar 3, 2020

The commit resolves all but has-through. I still need to look into this one.

@kiaking
Copy link
Member

kiaking commented Mar 3, 2020

Oh OK. Great. Thank you for working on it! 🤝

@cuebit cuebit self-assigned this Mar 5, 2020
@cuebit cuebit removed this from the v1.0.0 milestone Mar 5, 2020
@cuebit cuebit added the in progress The implementation is in progress label Mar 5, 2020
@kiaking kiaking added resolved Issue have been resolved but not yet released and removed in progress The implementation is in progress labels Mar 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working resolved Issue have been resolved but not yet released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants