where clause in left join?
where clause in left join?
moonjikLee
Posts: 6Questions: 1Answers: 0
Hello, does anyone know why this code doesn't work?
return new Editor(knex, table)
.fields(
new Field('DataFiles.id'),
new Field('DataFiles.Name')
.setFormatter(Format.ifEmpty(null))
.upload(
new Upload()
.action(async function(fileInfo){
// console.log(fileInfo);
let originalName = fileInfo.filename;
let splitName = originalName.split('.');
let tempName = + new Date();
let newName = splitName[0] + '_' + tempName + '.' + splitName[1];
let dirStrLength = fileInfo.file.length - originalName.length - 1 - "/upload".length;
busboyTempDir = fileInfo.file.slice(0,dirStrLength);
await rename(fileInfo.file, __dirname + '/../../infoboxRes/'+originalName);
return originalName;
})
),
new Field('DataFiles.RegDate'),
new Field('DataFiles.MainType'),
new Field('DataFiles.Title'),
new Field('DataFiles.FileType').options(
new Options().table('DataFileType').value('id').label('Comment')
),
new Field('DataFileType.Comment'),
new Field('DataFiles.Source').options(
new Options().table('DataSource').value('id').label('Source')
),
new Field('DataSource.Source'),
new Field('DataFiles.Location'),
new Field('DataFiles.Keyword'),
new Field('DataFiles.LangCode')
)
.leftJoin('DataFileType','DataFiles.FileType','=','DataFileType.id')
.leftJoin('DataSource','DataFiles.Source','=','DataSource.id')
.where('DataFiles.langCode', 'en');
when I remove .where clause, it works correctly, but adding .where clause, I got error message
null: TypeError: The operator "undefined" is not permitted
at Formatter.operator (/Users/leemoonjik/devel/jbkLab/repository/server/node_modules/knex/lib/formatter.js:203:13)
at QueryCompiler_MySQL.whereBasic (/Users/leemoonjik/devel/jbkLab/repository/server/node_modules/knex/lib/query/compiler.js:668:22)
at QueryCompiler_MySQL.where (/Users/leemoonjik/devel/jbkLab/repository/server/node_modules/knex/lib/query/compiler.js:386:34)
at /Users/leemoonjik/devel/jbkLab/repository/server/node_modules/knex/lib/query/compiler.js:118:69
at Array.map (<anonymous>)
at QueryCompiler_MySQL.select (/Users/leemoonjik/devel/jbkLab/repository/server/node_modules/knex/lib/query/compiler.js:118:35)
at QueryCompiler_MySQL.toSQL (/Users/leemoonjik/devel/jbkLab/repository/server/node_modules/knex/lib/query/compiler.js:64:29)
at Builder.toSQL (/Users/leemoonjik/devel/jbkLab/repository/server/node_modules/knex/lib/query/builder.js:77:44)
at /Users/leemoonjik/devel/jbkLab/repository/server/node_modules/knex/lib/runner.js:30:36
at /Users/leemoonjik/devel/jbkLab/repository/server/node_modules/knex/lib/runner.js:253:24
at tryCatcher (/Users/leemoonjik/devel/jbkLab/repository/server/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/leemoonjik/devel/jbkLab/repository/server/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/Users/leemoonjik/devel/jbkLab/repository/server/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/Users/leemoonjik/devel/jbkLab/repository/server/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/Users/leemoonjik/devel/jbkLab/repository/server/node_modules/bluebird/js/release/promise.js:729:18)
at _drainQueueStep (/Users/leemoonjik/devel/jbkLab/repository/server/node_modules/bluebird/js/release/async.js:93:12) {stack: 'TypeError: The operator "undefined" is not pe…e_modules/bluebird/js/release/async.js:93:12)', message: 'The operator "undefined" is not permitted'}
message: 'The operator "undefined" is not permitted'
What am I wrong with this?
Thanks.
This discussion has been closed.
Replies
In the Editor NodeJS libraries we basically pass your parameters to Knex. So what you can do with Knex's
where
method you can also do with Editor's - e.g. use:You should be able to do what you've done according to the Knex docs, so I'm honestly not sure what has gone wrong there! You could try:
what version of Knex are you using and what database type?
Allan