Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

    Create a relation between two LoopBack models

    loopbackLoopback
    ^3.0.0

    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.