Hi @jeffladiray,
Thanks a lot for your answer.
This is not working, I have an error like:
[forest] 🌳🌳🌳 Unexpected error: missing FROM-clause entry for table "idMaterial"
{
"name": "SequelizeDatabaseError",
"parent": {
"length": 122,
"name": "error",
"severity": "ERROR",
"code": "42P01",
"position": "275",
"file": "parse_relation.c",
"line": "3459",
"routine": "errorMissingRTE",
"sql": "SELECT \"id\", \"created_at\" AS \"createdAt\", \"updated_at\" AS \"updatedAt\", \"comment\", \"id_material\" AS \"idMaterialKey\", \"id_origin\" AS \"idOriginKey\" FROM \"public\".\"material_per_origin\" AS \"materialPerOrigin\" WHERE (lower(\"materialPerOrigin\".\"comment\") LIKE lower('%Glass%') OR \"idMaterial\".\"name\" ILIKE '%Glass%') LIMIT 10 OFFSET 0;"
[...]
Which is logical because when you look at the query :
SELECT "id", "created_at" AS "createdAt", "updated_at" AS "updatedAt", "comment", "id_material" AS "idMaterialKey", "id_origin" AS "idOriginKey" FROM "public"."material_per_origin" AS "materialPerOrigin" WHERE (lower("materialPerOrigin"."comment") LIKE lower('%Glass%') OR "idMaterial"."name" ILIKE '%Glass%') LIMIT 10 OFFSET 0
there is no mention of the table idMaterial
in the from clause. So I suppose that the includes are not working.
const Op = models.objectMapping.Op;
should work as expected, but maybe you’ve encounter an issue between the time we updated the documentation and this thread, as this should have been fixed following your previous thread.
Sorry I forgot to put a link, but I was talking about the Woodshop, about this page precisely https://docs.forestadmin.com/woodshop/how-tos/search-on-a-smart-field-with-joints#directory-forest.
I’m not sure of what you mean here.
models/index.js
should export all the models you need, just like it did in v6. I would be happy to take a look at yours to check if everything is setup correctly.
Sure, you can find the file here:
const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const databasesConfiguration = require('../config/databases');
const connections = {};
const db = {};
databasesConfiguration.forEach((databaseInfo) => {
const connection = new Sequelize(databaseInfo.connection.url, databaseInfo.connection.options);
connections[databaseInfo.name] = connection;
const modelsDir = databaseInfo.modelsDir || path.join(__dirname, databaseInfo.name);
fs
.readdirSync(modelsDir)
.filter((file) => file.indexOf('.') !== 0 && file !== 'index.js')
.forEach((file) => {
try {
const model = connection.import(path.join(modelsDir, file));
db[model.name] = model;
} catch (error) {
console.error('Model creation error: ' + error);
}
});
});
Object.keys(db).forEach((modelName) => {
if ('associate' in db[modelName]) {
db[modelName].associate(db);
}
});
db.objectMapping = Sequelize;
db.connections = connections;
module.exports = db;
Thanks for your help @jeffladiray, always appreciated!