feat(repository): introduce resolver and hasMany key inferrence with belongsTo decorator AND add belongsTo repository#1618
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
1st and 2nd commit: Type resolver and
keyToinferrenceThere is an issue with relation and decorators where model resolution doesn't occur properly. A short example to illustrate the problem:
When Customer is being defined, Order will be read and be attempted to be defined. As Order is being defined, it comes across Customer which has yet to be defined, so the metadata being stored by the decorators is incomplete at the time it's being stored.
The work around for this is to introduce a resolver; a resolver is a function that would return the given model when called. So instead of passing in the Models themselves these decorators, you would pass in their resolver instead:
@hasMany(() => Order)and@belongsTo(() => Customer).Another feature included in these commits is automatic building of hasMany metadata based on existing metadata on belongsTo. More specifically,
keyTois inferred from the name of the property key in which belongsTo metadata exists.In summary, this PR introduces:
@hasManyand@property.array)keyToinference from the key decorated by@belongsTo3rd commit: belongsTo repository
There is a problem where if belongsTo and hasMany relations are defined on the repositories, our context system will throw an error due to the cyclic dependence the relations create. To illustrate the example in a dirty dirty code snippet:
Take an event where customer repository needs to be instantiated. An injection on
orderRepowill attempted to be made and an order repository will be instantiated. When an order repository is being instantiated, a customer repository needs to be injected, and therefore a circular dependency is established.The solution to solving the dependency is to use a resolver like we did for the commits before. Take a look at this code snippet and this to see how the UX would look like. I'll probably work on introducing a decorator that won't promisify the repositories here.
related to #1361
Things that have not been done:
@inject.getterusage in our relation repositoriesChecklist
npm testpasses on your machinepackages/cliwere updatedexamples/*were updated