loopback-next icon indicating copy to clipboard operation
loopback-next copied to clipboard

Model relations

Open ashdns opened this issue 8 years ago • 7 comments

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.

ashdns avatar Dec 20 '17 02:12 ashdns

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.

shimks avatar Dec 20 '17 19:12 shimks

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 :(

ashdns avatar Dec 23 '17 13:12 ashdns

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.

ashdns avatar Dec 23 '17 13:12 ashdns

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 @belongsTo are 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:

  1. Build Repository classes for accessing related models, passing metadata from @belongsTo (and friends) to legacy juggler. For example, our DefaultCrudRepository creates a new backing PersistedModel from the definition provided by an Entity(a Model) annotated with decorators like @property. (source code).

  2. Come up with a convention for building Controller classes 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.

bajtos avatar Jan 02 '18 13:01 bajtos

Thanks for reply. I'm not sure if my TypeScript knowledge is enough to contribute in this project.

ashdns avatar Jan 03 '18 01:01 ashdns

@arash01 , we've opened a github issue on the spike: https://github.com/strongloop/loopback-next/issues/995.

dhmlau avatar Feb 26 '18 18:02 dhmlau

Duplicate of #995

dhmlau avatar Apr 10 '18 16:04 dhmlau