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.

Community
  • 1
  • 1
Bill
  • 384
  • 6
  • 20

1 Answers1

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)

Overdrivr
  • 6,296
  • 5
  • 44
  • 70