Skip to content

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

Open

Description

@vundev

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

Activity

  1. parse-github-assistant commented on Feb 9, 2025

    @parse-github-assistant

    Thanks for opening this issue!

  2. vundev commented on Feb 9, 2025

    @vundev
    Author

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

  3. added
    type:bugImpaired feature or lacking behavior that is likely assumed
    on Feb 9, 2025
  4. added a commit that references this issue on Jul 4, 2026
    c90c6e0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:bugImpaired feature or lacking behavior that is likely assumed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions