You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Can't define scopes in separate variables/files to use in the @DefaultScope and @Scope decorators #891
I'm submitting a ...
[x] bug report
[x] feature request
Actual behavior:
I am unable to use the decorators to define scopes for one of my models. It has quite a few relations and nested includes, so I have delcared them in a separate file
Expected behavior:
I expect the behavior to be the same regardless of where I create the scopes.
It would be nice to be able to create the scope definitions elsewhere and then pass them into the decorators. For example, I am combining a couple different scopes to avoid duplicate code, like this
changed the title [-]Inconsistent behavior between @Scopes and Model.addScope() with nested relations[/-][+]Inconsistent behavior between @DefaultScope and Model.addScope() with nested relations[/+]on Jan 26, 2021
changed the title [-]Inconsistent behavior between @DefaultScope and Model.addScope() with nested relations[/-][+]Can't define scopes in separate variables/files to use in the @DefaultScope and @Scope decorators[/+]on Jan 26, 2021
If it's still relevant, I figured out a way to make it work. I had the same issue with hooks. The key is to export a function that returns the scope definition rather that the object itself.
So, this works:
Activity
[-]Inconsistent behavior between @Scopes and Model.addScope() with nested relations[/-][+]Inconsistent behavior between @DefaultScope and Model.addScope() with nested relations[/+]Brobin commentedon Jan 26, 2021
I think I figured it out.
It appears that by defining the hooks in a separate file, or even in a variable does not work since it doesn't register
ModelBas a model[-]Inconsistent behavior between @DefaultScope and Model.addScope() with nested relations[/-][+]Can't define scopes in separate variables/files to use in the @DefaultScope and @Scope decorators[/+]Papooch commentedon Jun 22, 2021
If it's still relevant, I figured out a way to make it work. I had the same issue with hooks. The key is to export a function that returns the scope definition rather that the object itself.
So, this works:
I think it has to do with how node resolves circular dependencies or something...
lan-nguyen91 commentedon Dec 25, 2022
@Papooch your solution works 👏