Hi Forest!
We’re dealing with a weird behaviour…
We have a sequelize model with a relationship.
In the relationship we have a scope (see Association Scopes | Sequelize).
When we “use” this relationship through sequelize, in the underlying sql query we can see the scope implemented correctly in the WHERE
clause (indented for reading):
... WHERE (
"MyModel"."deleted_at" IS NULL
AND (
NOT ("MyModel"."id_fk" IS NULL)
AND "MyModel"."id_fk" IS NULL)
)
)
When the very same relationship is “used” by forest, then the scope is ignored. Here is the WHERE
clause in this case:
WHERE (
"MyModel"."deleted_at" IS NULL
AND "MyModel"."id_fk" IS NULL
)
Here is the definition of the relationship:
...
hasMany(models.MyModel, {
as: 'myAliasName',
foreignKey: ...
sourceKey: ...
scope: {
[Op.not]: {
idFk: null,
},
},
})
...
Therefore, my question is: are the sequalize relationship scopes supported in @forestadmin/datasource-sequelize
and @forestadmin/agent
?
As far as I can remember, they used to work in forest-express-sequelize
…
Thank you in advance for a check,
Matteo
Our versions
From .forestadmin-schema.json
:
"meta": {
"liana": "forest-nodejs-agent",
"liana_version": "1.60.1",
"liana_features": null,
"stack": {"engine": "nodejs", "engine_version": "20.12.2"}
}
From package.json
:
...
"@forestadmin/agent": "^1.60.1",
"@forestadmin/datasource-sequelize": "^1.12.1",
"sequelize": "^6.28.0",
...