How to include and order an array using the Strongloop Loopback REST API?

Eli

I have am including an array in an existing model, by adding the terms {"include" : ["answers"]} in a model called User/Questions. Therefore, if I get the User/Questions model I will get a list of answers. However, now I would like to order the answers in my Question Model based on the dateCreated. To do this how should I edit the terms I place in the REST Strongloop API's filter?

//QuestionModel

[
{
"question": "where is the coffee shop?"
"answers": [
 //answer model included
  {
    "answer": "I am not sure",
    "dateCreated": 4/1/16,
  },
 {
    "answer": "maybe try 5th avenue?",
    "dateCreated": 4/3/16,
  },
  {
    "answer": "oh its by the bakery",
    "dateCreated": 4/2/16,
  }
]
user465342

Scope need to be included when When querying related models. So for your example, it would be along the lines of:

 {"include": {"relation": "answers", "scope": {"order" : "dateCreated DESC"}}}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Using Non-Rest Calls with Loopback (Strongloop)

From Dev

how to filter data in include 'model' using strongloop

From Dev

Change the array/collection order using a REST API

From Dev

Best Practices for API calls in strongloop loopback

From Dev

How to order a subnet using Softlayer REST API?

From Dev

How to filter data using loopback include relation?

From Dev

How to Modify the StrongLoop's LoopBack Explorer CSS

From Dev

How to create hook in strongloop loopback for soft delete

From Dev

How to change http status codes in Strongloop Loopback

From Dev

How to include related entities in REST with loopback.io

From Dev

Loopback Connector REST API

From Dev

How to upload file using loopback api explorer?

From Dev

Best way to store geojson data using loopback for rest api

From Dev

Implementing Q with Strongloop Loopback

From Dev

Persist Users in Strongloop Loopback

From Dev

StrongLoop Loopback Yeoman Angular

From Dev

Createmany in Strongloop Loopback

From Dev

Strongloop/Loopback connector for gRPC

From Dev

StrongLoop : How to define models in models/ directory at loopback.boot() time?

From Dev

How to configure StrongLoop LoopBack MongoDB datasource for deployment to Heroku

From Dev

strongloop loopback: how to save many-to-many relationship

From Dev

How to override base User in a Strongloop loopback scaffolded project?

From Dev

Strongloop loopback how to assign static roles to new users

From Dev

How to run multiple StrongLoop LoopBack apps on the same server?

From Dev

How to configure two different datasource for a model in Strongloop Loopback framework?

From Dev

How to use REPL to test Strongloop-Loopback query

From Dev

How to use the hint operator from mongoDB in strongloop loopback?

From Dev

Using the LoopBack API Explorer

From Dev

Using the LoopBack API Explorer

Related Related

  1. 1

    Using Non-Rest Calls with Loopback (Strongloop)

  2. 2

    how to filter data in include 'model' using strongloop

  3. 3

    Change the array/collection order using a REST API

  4. 4

    Best Practices for API calls in strongloop loopback

  5. 5

    How to order a subnet using Softlayer REST API?

  6. 6

    How to filter data using loopback include relation?

  7. 7

    How to Modify the StrongLoop's LoopBack Explorer CSS

  8. 8

    How to create hook in strongloop loopback for soft delete

  9. 9

    How to change http status codes in Strongloop Loopback

  10. 10

    How to include related entities in REST with loopback.io

  11. 11

    Loopback Connector REST API

  12. 12

    How to upload file using loopback api explorer?

  13. 13

    Best way to store geojson data using loopback for rest api

  14. 14

    Implementing Q with Strongloop Loopback

  15. 15

    Persist Users in Strongloop Loopback

  16. 16

    StrongLoop Loopback Yeoman Angular

  17. 17

    Createmany in Strongloop Loopback

  18. 18

    Strongloop/Loopback connector for gRPC

  19. 19

    StrongLoop : How to define models in models/ directory at loopback.boot() time?

  20. 20

    How to configure StrongLoop LoopBack MongoDB datasource for deployment to Heroku

  21. 21

    strongloop loopback: how to save many-to-many relationship

  22. 22

    How to override base User in a Strongloop loopback scaffolded project?

  23. 23

    Strongloop loopback how to assign static roles to new users

  24. 24

    How to run multiple StrongLoop LoopBack apps on the same server?

  25. 25

    How to configure two different datasource for a model in Strongloop Loopback framework?

  26. 26

    How to use REPL to test Strongloop-Loopback query

  27. 27

    How to use the hint operator from mongoDB in strongloop loopback?

  28. 28

    Using the LoopBack API Explorer

  29. 29

    Using the LoopBack API Explorer

HotTag

Archive