1

I am looking for a way to include the result of a remote method when I make a query.

For example: I am querying Customer models. To include a related model you would use the include filter { filter: { include: ['orders'] } }.

I need to do some processing on some related models before returning results.

What I am looking for is something akin to virtual properties from Mongoose. Is this possible or do I have to create a separate request for each customer after results returned?

Berkeley Martinez
  • 2,786
  • 2
  • 14
  • 18

1 Answers1

0

You can extend the model class and add properties with getter function so that it will get values from other persisted properties.

For example:

module.exports = function(Person) {
  Object.defineProperty(Person.prototype, 
    "fullName", 
    {
      get : function() { return this.firstName + ' ' + this.lastName; }
    });
}

http://docs.strongloop.com/display/LB/Extend+your+API

Raymond Feng
  • 1,516
  • 9
  • 5
  • This would give me a method on the Person object, but would that method be available on the generated ngResource object? – Berkeley Martinez Oct 18 '14 at 03:17
  • I have a follow up question about this approach [here](http://stackoverflow.com/questions/28840693/loopback-include-a-relations-computed-properties). – Michael.Lumley Mar 03 '15 at 19:50