Skip to content

Specifying another model's scope #43

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

Closed
Pritilender opened this issue Jul 6, 2017 · 2 comments
Closed

Specifying another model's scope #43

Pritilender opened this issue Jul 6, 2017 · 2 comments
Assignees
Labels

Comments

@Pritilender
Copy link

Pritilender commented Jul 6, 2017

I have two models in n:m association, A and B, and third one in association with A in 1:n association. Default scope of B has include: [() => C] but I want to specify in default scope of A not to include C when loading B, so I created a new scope on B which doesn't include C.

Sequelize docs says that you can say B.scope('scopeName') (the last example in this section). When I try to do that like include: [() => B.scope('scopeName')], I get next error on app start:

Invalid scope scopeName called.
     at /node_modules/sequelize/lib/model.js:1224:13
     at Array.forEach (native)....

I've noticed that it can be due to the fact that A comes before B, so when the lib tries to load model A it hasn't loaded model B yet so it's logical why is this scope invalid.

But when I change the order of model loading (A becomes B and B becomes A), I get another error:

TypeError: self.$expandAttributes is not a function
     at conformOptions (/node_modules/sequelize/lib/model.js:250:10)
     at conformInclude (/node_modules/sequelize/lib/model.js:307:5)

So my question is if this scoped include is supported in sequelize-typescript or not? And if it is, what's the syntax?

EDIT: I forgot to mention I'm using v3 of Sequelize.

@RobinBuschmann
Copy link
Member

Hey @Pritilender, seems like a bug to me and I guess it is related to #37 . I will investigate this on next weekend. Thanks for reporting.

@Pritilender
Copy link
Author

Yes, I've noticed #37 also today (therefore the 'thumbs up' reaction 😃).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants