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

Relational query with .limit() and descending order does not work as expected. #9600

Open
vundev opened this issue Feb 9, 2025 · 2 comments
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@vundev
Copy link

vundev commented Feb 9, 2025

Issue Description

I have two parse classes User and Post. The user class has relation named posts containing Post objects. When i do
the following query

user.relation("posts", className: Post.className) .query(Post()) .limit(5) .order(.descending("createdAt"))

i got less than 5 objects nevertheless the user has more than 5 posts.

Steps to reproduce

  1. Creates 6 posts, let say post 1, post 2, ..., post 6. Post[i] is created before Post[i+1].
  2. Delete the last created post (post 6).
  3. Then run the provided query with limit 5.

Actual Outcome

The query returns post 5, post 4, post 3 and post 2 (total of 4 posts).

Expected Outcome

My expectation is that the query will omit the deleted object and return the first 5 available objects - post 5 up to post 1.
This happens because the join table representing the relation keeps the id of the deleted object. The limit operator gives 5 object ids including the id of the deleted object. I consider this a bug.

Server

  • Parse Server version: 4.10.4
  • Operating system: macOS
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): Local/Heroku

Database

  • System (MongoDB or Postgres): MongoDB
  • Database version: 8.0.4
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): MongoDB Atlas

Client

  • SDK (iOS, Android, JavaScript, PHP, Unity, etc): iOS
  • SDK version: 3.1.0
Copy link

Thanks for opening this issue!

@vundev
Copy link
Author

vundev commented Feb 9, 2025

One workaround i can think of is:
Post.query().where(matchesKeyInQuery(key: "objectId", queryKey: "objectId", query: user.relation("posts", className: Post.className) .query(Post()))) .limit(5) .order(.descending("createdAt"))

@mtrezza mtrezza added the type:bug Impaired feature or lacking behavior that is likely assumed label Feb 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

No branches or pull requests

2 participants