1

In a situation similar to this one, Getting joined data from strongloop/loopback, where one has Products and product Categories, how does one return the Category Name rather than the id (foreign key) as the default response for /Products? I've been able to hide the id field but not return the name. Thanks.

1
  • Is your problem solved ?
    – Overdrivr
    Jan 12, 2017 at 12:05

1 Answer 1

1

Supposing you have the relation Product hasOne Category, called productCat

With Node API

Product.find({
 include: {
    relation: 'productCat', // include the Category object
    scope: { // further filter the Category object
      fields: 'name', // only show category name
    }
  }
}, function(err, results) { /* ... */});

With REST API

GET api/Products?filter={"include":{"relation":"productCat","scope":{"fields":"name"}}}

Hope this helps (haven't tested it but it should work)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.