loopback 3 get all relations code example

Example 1: loopback include multiple relations

Post.find({
  include: {
    relation: 'owner', // include the owner object
    scope: { // further filter the owner object
      fields: ['username', 'email'], // only show two fields
      include: { // include orders for the owner
        relation: 'orders', 
        scope: {
          where: {orderId: 5} // only select order with id 5
        }
      }
    }
  }
}, function() { /* ... */ });

Example 2: loopback 3 includes many

User.find({include: ['posts', 'orders']}, function() { /* ... */ });

Tags:

Html Example