This Lesson is for PRO Members.

Subscribe today and get access to all lessons! Plus direct HD download
for offline use, member comment forums, and iTunes "podcast" RSS feed.
Level up your skills now!

UNLOCK THIS LESSON

Already subscribed? Sign In

HIDE PLAYLIST

Create a relation between two LoopBack models


A relation in LoopBack is a way to associate the data from multiple models with each other. LoopBack supports various types of relations each with a different use case.

In this lesson we will create a second model called Category and create a relation between the Category and the Product models. To do this we will first add a property to the Product model called categoryId. This will allow us to store for each Product the category it belongs to. We then move on to create the actual relationships.

Our first relationship defines that a Category hasMany Products and the second one that a Product belongsTo a Category.

After defining these relations we will use the API Explorer to see how we can interact with this related data.