include models only when it is a single query

19 views
Skip to first unread message

Jibuti

unread,
May 29, 2015, 5:51:18 AM5/29/15
to loopb...@googlegroups.com
now I have api/books

[
  {
    "title": "book1",
     "author": {
       "name": "Author.1"
     }
  },
  {
    "title": "book2",
     "author": {
       "name": "Author.2"
     }
  },
]


but i want to have 

[
  {"title": "book1"},
  {"title": "book2"},
]

And only if i do api/books/1 want to have embedded model 'Author'

  {
    "title": "book1",
     "author": {
       "name": "Author.1"
     }
  }

Jibuti

unread,
May 29, 2015, 6:02:36 AM5/29/15
to loopb...@googlegroups.com
my question is how to do it (if it even possible) in model config JSON file

James Green

unread,
May 29, 2015, 7:15:11 AM5/29/15
to loopb...@googlegroups.com

On 29 May 2015 at 11:02, Jibuti <a.schwe...@gmail.com> wrote:
my question is how to do it (if it even possible) in model config JSON file

--
You received this message because you are subscribed to the Google Groups "LoopbackJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to loopbackjs+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jibuti

unread,
May 30, 2015, 8:53:08 AM5/30/15
to loopb...@googlegroups.com
@James Green 
yes, I'm aware about modifying the format of the response. I guess I should use the context's query (URL) parameter to find out if it is a given book, 
or all books are asked, and format the response accordingly.

But my question again: is it possible to set this in the model's config file? (book.json)
Reply all
Reply to author
Forward
0 new messages