Skip to content

Allow a query to sort based on an object value field #4805

Closed

Description

@acinader

Currently, if one tries to sort a query on a field in an object field, parse generates an error:

Type: Parse\ParseException
Code: 105
Message: Invalid field name: trendRankTopic.popular.

due to the check in the database controller here:

if (!SchemaController.fieldNameIsValid(fieldName)) {

This is not the same, though related to: #2113

An example would be an object:

{ sortField: { value: 10 } }

with a Query:

new Parse.Query('Test').addAscending('sortField.value').first()

generates the above error

Activity

  1. flovilmart commented on Jun 1, 2018

    @flovilmart
    Contributor

    What error would do you expect? Or would you expect sorting to work on objects?

  2. acinader commented on Jun 1, 2018

    @acinader
    ContributorAuthor

    one sec and I'll open the pr with the failing test and my proposed solution :).

  3. flovilmart commented on Jun 1, 2018

    @flovilmart
    Contributor

    Even better :)

  4. acinader commented on Jun 7, 2018

    @acinader
    ContributorAuthor

    @flovilmart any thoughts on #4806

    I'm currently running our production on that branch which ain't a great long-term solution.

    Anything I can explain as to why its an issue in the first place
    or the solution I chose and why.

    Some things I'd appreciate your considering: Is there a use case that this change would cause a breakage? is there a use case where my change will allow an introduction of 'bad schema' that could cause mayhem? Is there coverage I could write to test?

    And finally, any suggestion on who I might ping to look at why Postgress is failing my test and what a solution might be?

  5. flovilmart commented on Jun 7, 2018

    @flovilmart
    Contributor

    I don’t think it’s a bad idea to introduce sorting on nested keys, Postgres support could come later. It can be gated with it_only_db instead of a simple it.

    I don’t believe it is something we may regret in then future, however, I’m quite not understanding the change / i believe it’s not the proper resolution :)

  6. acinader commented on Jun 7, 2018

    @acinader
    ContributorAuthor

    I'll gate the test and add more explanation to the pull request. I agree that it is low risk. Having looked at it, I do think its the right solution, however, I'm super mindful of the fact that my ability to reason about that code is pretty limited :). Thanks!

  7. flovilmart commented on Jun 7, 2018

    @flovilmart
    Contributor

    CAN we add a small comment as for the change then in the code? So anyone that stumbled upon it is able to get a good idea of what’s going on?

  8. acinader commented on Jun 7, 2018

    @acinader
    ContributorAuthor

    done.

  9. wret commented on Jul 21, 2018

    @wret

    Sorting based on object still not working on version 2.8.2.

  10. NicksonYap commented on Oct 2, 2018

    @NicksonYap

    @wret
    It is enabled in 2.8.4: "Allow sorting an object field (#4806)"
    https://github.com/parse-community/parse-server/blob/2.8.4/CHANGELOG.md

    However, it does not seem like it's supposed to order by related object's field

    Tried this and has totally no effect:

          query.include('subzone');
          query.include('subzone.zone'); 
          query.addAscending('subzone.zone.title')  //no effect on result, no error
          query.addAscending('subzone.title') //no effect on result, no error
          query.addAscending('title') //sorts by title
    

    @flovilmart @acinader
    After upgrading from 2.8.2 to 2.8.4 query.ascending() no longer reports any error if the field does not exist
    is it because of this sort by object field feature?

  11. locked and limited conversation to collaborators on Aug 2, 2022
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions