docs/site/migration/models/relations.md
{% include tip.html content=" Missing instructions for your LoopBack 3 use case? Please report a Migration docs issue on GitHub to let us know. " %}
When you define a relation in a LoopBack 3 model JSON file, the framework will create the following artifacts for you automatically:
Category.prototype.products.Product.find({include: ['category']})GET /api/categories/1/products.In LoopBack 4, these building blocks are typically provided by the application developer.
@hasMany.At the moment, all of these artifacts are defined via source code files which
are typically created by running lb4 relation. With source code files ready to
be edited, developers get a lot of power and flexibility in customizing the
default behavior offered by the framework.
In the future, we would like to provide a declarative approach for building model relations: the developer defines relation metadata, and the framework builds all required artifacts at runtime, similar to how LoopBack 3 works. You can join the discussion in the GitHub issue loopback-next#2483.
Follow these steps to migrate a model relation from LoopBack 3 to LoopBack 4:
Make sure to complete all steps described in Migrating model definitions and built-in APIs, especially the creation of Repository classes for models on both sides of the relation.
Run lb4 relation to define the model relation in your model class, generate
code for the relation repository and optionally register inclusion resolver.
This command will also create a new Controller class implementing public REST
API for your relation.
You can learn more about lb4 relation command in
Relation generator.
The following relations are supported by LoopBack 4 and can be migrated from LoopBack 3:
Other relations types are not supported yet, you can subscribe to our progress in the high-level tracking issue loopback-next#1450. See also issues for individual relation types as mentioned in the tracking issue, for example: