Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect cyclic dependencies in property definitions #1799

Closed
bajtos opened this issue Oct 4, 2018 · 3 comments
Closed

Detect cyclic dependencies in property definitions #1799

bajtos opened this issue Oct 4, 2018 · 3 comments
Labels
feature Relations Model relations (has many, etc.) Repository Issues related to @loopback/repository package stale

Comments

@bajtos
Copy link
Member

bajtos commented Oct 4, 2018

While working on belongsTo relation in #1618, we discovered a need to detect circular dependencies in property definitions and provide a helpful error to users.

Here is a PoC code that did not make it to master yet:

https://github.com/strongloop/loopback-next/blob/bcd7ee98cc4958ccde595cf26e35e6f53f236401/packages/repository/src/decorators/model.decorator.ts#L90-L110

We should take a closer look at different ways how a cyclic relation can be introduced, write tests to reproduce those cases and then fix the implementation to throw an error that explains the user what went wrong and how to fix the problem.

Acceptance criteria

TBD

@bajtos bajtos added feature Relations Model relations (has many, etc.) Repository Issues related to @loopback/repository package labels Oct 4, 2018
@bajtos
Copy link
Member Author

bajtos commented Oct 4, 2018

Few examples of different ways how to create a cyclic dependency. Some of them are rejected by the compiler if all code is in the single file (but may not be detected if each model has its own source code file).

Property types read from design:type metadata:

class Wife {
 @property()
 husband: Husband;
}

class Husband {
  @property()
  wife: Wife;
}

Property types specified explicitly via a model class:

class Wife {
 @property({type: Husband})
 husband: Husband;
}

class Husband {
  @property({type: Wife})
  wife: Wife;
}

@stale
Copy link

stale bot commented Sep 29, 2019

This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository. This issue will be closed within 30 days of being stale.

@stale stale bot added the stale label Sep 29, 2019
@stale
Copy link

stale bot commented Oct 29, 2019

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

@stale stale bot closed this as completed Oct 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Relations Model relations (has many, etc.) Repository Issues related to @loopback/repository package stale
Projects
None yet
Development

No branches or pull requests

1 participant