Page 1 of 1

Distinct query sorted by Create Date for logged on user

Posted: Fri Oct 17, 2014 10:00 am
by Adrian Stoch

The use case is as follows:

  • User can enter 1 or many comments on a post

  • User then wants to see a list of the posts they have commented on (the list must be distinct based on post ID to only show each post once)

  • The list is sorted to show most recent comments he has made first

    I am therefore attempting a query that:

  • Returns distinct values of the post ID

  • Where user = logged on user

  • In descending created date order

    When the query is a POST it ignores the where and sort parameters:
    Image
    Image

    When the query is a GET I receive the below error:
    Image
    Image


Distinct query sorted by Create Date for logged on user

Posted: Fri Oct 17, 2014 2:26 pm
by Evgene Karachevtsev

Hello Adrian,

When you use the GET method you should add header parameter Content-Type with a value of application/json.
For more information, please see the documentation http://devcenter.appery.io/documentat...


Distinct query sorted by Create Date for logged on user

Posted: Fri Oct 17, 2014 2:37 pm
by Adrian Stoch

Thanks Evgene, I missed the Content-Type setting in the Curl command.

That has fixed the where condition, but the sort is still not working. As you can see in the 3 screenshots below, the order remains the same irrespective of the sort parameter. I believe it is defaulting to ascending _createdAt. I need the order in descending _createdAt so the user sees latest comments first.

Image
Image
Image


Distinct query sorted by Create Date for logged on user

Posted: Sat Oct 18, 2014 4:04 am
by obullei

Hello!

Please note that when you get the distinct values ​​, the sort parameter is ignored
Please take a look here: http://stackoverflow.com/a/18478924
So, you can only get the desired column http://devcenter.appery.io/documentat... (sorting will work with query)
and select from all obtained values ​​using the unique JS (which may be implemented in the server code, or by means of generic services)


Distinct query sorted by Create Date for logged on user

Posted: Sat Oct 18, 2014 2:51 pm
by Adrian Stoch

Thank Arina, but I looked through the documentation of the Projection and can not see where the unique JS is described. Can you please point me in the direction of where this is explained how to implement.


Distinct query sorted by Create Date for logged on user

Posted: Mon Oct 20, 2014 2:35 am
by Yurii Orishchuk

Hi Adrian,

There is no code example for JS(server code). So you should implement it yourself.
Here is documentation:
1 Tutorial: http://devcenter.appery.io/tutorials/...
2 Server code docs: http://devcenter.appery.io/documentat...

Regards.