Skip to content

Specifying another model's scope #43

Closed
@Pritilender

Description

@Pritilender

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.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions