loopback include multiple 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 relation include to json

Post.find({include: {owner: [{posts: 'images'} , 'orders']}}, function(err, posts) {
 posts.forEach(function(post) {
   // post.owner points to the relation method instead of the owner instance
   var p = post.toJSON();
   console.log(p.owner.posts, p.owner.orders);
 });
 //... 
});

Example 3: loopback relations include inside include

<ion-datetime displayFormat="HH:mm" [(ngModel)]="myDate" minuteValues="0,30">

Example 4: loopback 3 includes many

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

Example 5: loopback relations include inside include

// Return all post owners (users), and all posts and orders of
// each owner. The posts also include images.
Post.find({include: {owner: [{posts: 'images'} , 'orders']}}, 
          function() { /* ... */ });

Example 6: loopback include relation

in url:
/customers?filter[include]=reviews

in code:
User.find({include: 'reviews'}, function() { /* ... */ });