djheru djheru - 3 years ago 168
Node.js Question

How to include related entities in REST with

I'm using Strongloop's loopback tool to create a REST service. I'm wondering how to define what related entities to return when requesting a model.

I see in the docs that you can send a request like

GET /api/members?filter[include]=posts
and that will return the related post models, and I discovered that you can make a request like
GET /api/members?filter[include]=posts&filter[include]=comments
to get posts and comments, but is there a way to define either in code or the generated json file that you'd like a certain relation to always be returned when requesting a model?

Answer Source

The preset filter properties are referred as default scope. We have a pending pull request to support that. Please see

As a workaround before the feature is released, you can use beforeRemote hooks to update the filter object with your default scope. See

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download