Model relations
I was wondering if model relations are implemented in current version or not yet? I see some decorators such as @ belongsTo in source code but couldn't find any documentation about using them.
Currently there is no implementation for model relations. To stay up-to-date on its release, please follow https://github.com/strongloop/loopback-next/issues/537.
I wish we had this feature on current release because without model relations, it's almost impossible for me to continue developing and testing on Loopback-Next :(
Also as a friendly suggestion, please don't close an issue as soon as you post a reply. Keeping an issue open for short period of time gives opportunity to other users to be involved in discussion.
I'd like to reopen this issue.
In #537, we reached the conclusion that we are going to keep Juggler around, but we would like to eventually simplify both the features provides and the codebase. In that light I think it makes sense to discuss how to expose relations in LoopBack 4.
Here is my understanding of the current status:
- Decorators like
@belongsToare just dummy placeholders not doing anything. - We don't have any helpers for exposing relation methods via REST API (or gRPC, etc.)
IMO, in order to make relations happen, two changes are needed:
-
Build
Repositoryclasses for accessing related models, passing metadata from@belongsTo(and friends) to legacy juggler. For example, ourDefaultCrudRepositorycreates a new backingPersistedModelfrom the definition provided by anEntity(aModel) annotated with decorators like@property. (source code). -
Come up with a convention for building
Controllerclasses exposing relation methods via REST API. See https://github.com/strongloop/loopback-next/pull/740 for an inspiration. Eventually, there should be a CLI tool for generating these controllers whenever an app developer is adding a new relation.
@arash01 I am afraid support for relations is pretty down in our priority list. Would you like to contribute this feature yourself? We are happy to help you along the way.
Thanks for reply. I'm not sure if my TypeScript knowledge is enough to contribute in this project.
@arash01 , we've opened a github issue on the spike: https://github.com/strongloop/loopback-next/issues/995.
Duplicate of #995