Node.js datatables editor - How to use a (knex) VIEW that composes a join
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'm using the node.js datatable editor library. When trying to do a complex left join 'portfolios_isin_mm.isin AND (securities.mic = portfolios_isin_mm.mic)' ... like this:
let editor = new Editor( db, 'portfolios_isin_mm' )
.fields(
new Field( 'portfolios_isin_mm.account_id' ),
new Field( 'portfolios_isin_mm.user_id' ),
new Field( 'portfolios_isin_mm.uid_foreign' )
new Field( 'securities.issuer_name' ),
new Field( 'portfolios_isin_mm.isin' ),
new Field( 'portfolios_isin_mm.mic' ),
)
.leftJoin( 'portfolios_isin', 'portfolios_isin.id', '=', 'portfolios_isin_mm.uid_foreign' )
.leftJoin( 'securities', 'securities.isin', '=', 'portfolios_isin_mm.isin AND (securities.mic = portfolios_isin_mm.mic)' );
//.leftJoin( 'securities', 'securities.isin', '=', 'portfolios_isin_mm.isin' );
I'm getting an error. Debugging the error shows me:
{ Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.`mic)`' at line 1
at Query.Sequence._packetToError (/home/myproject/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
at Query.ErrorPacket (/home/myproject/node_modules/mysql/lib/protocol/sequences/Query.js:77:18)
at Protocol._parsePacket (/home/myproject/node_modules/mysql/lib/protocol/Protocol.js:278:23)
at Parser.write (/home/myproject/node_modules/mysql/lib/protocol/Parser.js:76:12)
at Protocol.write (/home/myproject/node_modules/mysql/lib/protocol/Protocol.js:38:16)
at Socket.<anonymous> (/home/myproject/node_modules/mysql/lib/Connection.js:91:28)
at Socket.<anonymous> (/home/myproject/node_modules/mysql/lib/Connection.js:502:10)
at Socket.emit (events.js:182:13)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:264:11)
at Socket.Readable.push (_stream_readable.js:219:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
--------------------
at Protocol._enqueue (/home/myproject/node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Connection.query (/home/myproject/node_modules/mysql/lib/Connection.js:200:25)
at /home/myproject/node_modules/knex/lib/dialects/mysql/index.js:152:18
at Promise._execute (/home/myproject/node_modules/bluebird/js/release/debuggability.js:313:9)
at Promise._resolveFromExecutor (/home/myproject/node_modules/bluebird/js/release/promise.js:483:18)
at new Promise (/home/myproject/node_modules/bluebird/js/release/promise.js:79:10)
at Client_MySQL._query (/home/myproject/node_modules/knex/lib/dialects/mysql/index.js:146:12)
at Client_MySQL.query (/home/myproject/node_modules/knex/lib/client.js:197:17)
at Runner.<anonymous> (/home/myproject/node_modules/knex/lib/runner.js:146:36)
at Runner.tryCatcher (/home/myproject/node_modules/bluebird/js/release/util.js:16:23)
at Runner.query (/home/myproject/node_modules/bluebird/js/release/method.js:15:34)
at /home/myproject/node_modules/knex/lib/runner.js:65:21
at tryCatcher (/home/myproject/node_modules/bluebird/js/release/util.js:16:23)
at /home/myproject/node_modules/bluebird/js/release/using.js:185:26
at tryCatcher (/home/myproject/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/home/myproject/node_modules/bluebird/js/release/promise.js:512:31)
code: 'ER_PARSE_ERROR',
errno: 1064,
sqlMessage:
'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.`mic)`' at line 1',
sqlState: '42000',
index: 0,
sql:
'select count(`portfolios_isin_mm`.`id`) as `cnt` from `portfolios_isin_mm` left join `portfolios_isin` on `portfolios_isin`.`id` = `portfolios_isin_mm`.`uid_foreign` left join `securities` on `securities`.`isin` = `portfolios_isin_mm`.`isin AND (securities`.`mic = portfolios_isin_mm`.`mic)`' }
... with the php libraries it was working just fine:
->leftJoin( 'securities', 'securities.isin', '=', 'portfolios_isin_mm.isin AND (securities.mic = portfolios_isin_mm.mic)' )
Supposedly I can quote 'The only way to do this at the moment is to create a VIEW that composes that join then you can select from that view. The readTable (https://editor.datatables.net/docs/1.8.1/nodejs/classes/editor.editor.html#readtable) method can be used to read information from the view while still updating to the host table.'
How can I get the complex left join to work in node.js as well (using a VIEW that composes that join (using knex))?
... I'm using $ node -v ... v10.15.0 and "datatables.net-editor-server": "^1.8.1"
javascript node.js datatables knex.js
add a comment |
I'm using the node.js datatable editor library. When trying to do a complex left join 'portfolios_isin_mm.isin AND (securities.mic = portfolios_isin_mm.mic)' ... like this:
let editor = new Editor( db, 'portfolios_isin_mm' )
.fields(
new Field( 'portfolios_isin_mm.account_id' ),
new Field( 'portfolios_isin_mm.user_id' ),
new Field( 'portfolios_isin_mm.uid_foreign' )
new Field( 'securities.issuer_name' ),
new Field( 'portfolios_isin_mm.isin' ),
new Field( 'portfolios_isin_mm.mic' ),
)
.leftJoin( 'portfolios_isin', 'portfolios_isin.id', '=', 'portfolios_isin_mm.uid_foreign' )
.leftJoin( 'securities', 'securities.isin', '=', 'portfolios_isin_mm.isin AND (securities.mic = portfolios_isin_mm.mic)' );
//.leftJoin( 'securities', 'securities.isin', '=', 'portfolios_isin_mm.isin' );
I'm getting an error. Debugging the error shows me:
{ Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.`mic)`' at line 1
at Query.Sequence._packetToError (/home/myproject/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
at Query.ErrorPacket (/home/myproject/node_modules/mysql/lib/protocol/sequences/Query.js:77:18)
at Protocol._parsePacket (/home/myproject/node_modules/mysql/lib/protocol/Protocol.js:278:23)
at Parser.write (/home/myproject/node_modules/mysql/lib/protocol/Parser.js:76:12)
at Protocol.write (/home/myproject/node_modules/mysql/lib/protocol/Protocol.js:38:16)
at Socket.<anonymous> (/home/myproject/node_modules/mysql/lib/Connection.js:91:28)
at Socket.<anonymous> (/home/myproject/node_modules/mysql/lib/Connection.js:502:10)
at Socket.emit (events.js:182:13)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:264:11)
at Socket.Readable.push (_stream_readable.js:219:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
--------------------
at Protocol._enqueue (/home/myproject/node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Connection.query (/home/myproject/node_modules/mysql/lib/Connection.js:200:25)
at /home/myproject/node_modules/knex/lib/dialects/mysql/index.js:152:18
at Promise._execute (/home/myproject/node_modules/bluebird/js/release/debuggability.js:313:9)
at Promise._resolveFromExecutor (/home/myproject/node_modules/bluebird/js/release/promise.js:483:18)
at new Promise (/home/myproject/node_modules/bluebird/js/release/promise.js:79:10)
at Client_MySQL._query (/home/myproject/node_modules/knex/lib/dialects/mysql/index.js:146:12)
at Client_MySQL.query (/home/myproject/node_modules/knex/lib/client.js:197:17)
at Runner.<anonymous> (/home/myproject/node_modules/knex/lib/runner.js:146:36)
at Runner.tryCatcher (/home/myproject/node_modules/bluebird/js/release/util.js:16:23)
at Runner.query (/home/myproject/node_modules/bluebird/js/release/method.js:15:34)
at /home/myproject/node_modules/knex/lib/runner.js:65:21
at tryCatcher (/home/myproject/node_modules/bluebird/js/release/util.js:16:23)
at /home/myproject/node_modules/bluebird/js/release/using.js:185:26
at tryCatcher (/home/myproject/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/home/myproject/node_modules/bluebird/js/release/promise.js:512:31)
code: 'ER_PARSE_ERROR',
errno: 1064,
sqlMessage:
'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.`mic)`' at line 1',
sqlState: '42000',
index: 0,
sql:
'select count(`portfolios_isin_mm`.`id`) as `cnt` from `portfolios_isin_mm` left join `portfolios_isin` on `portfolios_isin`.`id` = `portfolios_isin_mm`.`uid_foreign` left join `securities` on `securities`.`isin` = `portfolios_isin_mm`.`isin AND (securities`.`mic = portfolios_isin_mm`.`mic)`' }
... with the php libraries it was working just fine:
->leftJoin( 'securities', 'securities.isin', '=', 'portfolios_isin_mm.isin AND (securities.mic = portfolios_isin_mm.mic)' )
Supposedly I can quote 'The only way to do this at the moment is to create a VIEW that composes that join then you can select from that view. The readTable (https://editor.datatables.net/docs/1.8.1/nodejs/classes/editor.editor.html#readtable) method can be used to read information from the view while still updating to the host table.'
How can I get the complex left join to work in node.js as well (using a VIEW that composes that join (using knex))?
... I'm using $ node -v ... v10.15.0 and "datatables.net-editor-server": "^1.8.1"
javascript node.js datatables knex.js
This ought to work fine. But what I noticed was that there are some syntax errors in the generated sql query:
– Olantobi
Jan 3 at 11:25
Yes. But how to solve it to make it work?
– Philipp M
Jan 3 at 11:48
add a comment |
I'm using the node.js datatable editor library. When trying to do a complex left join 'portfolios_isin_mm.isin AND (securities.mic = portfolios_isin_mm.mic)' ... like this:
let editor = new Editor( db, 'portfolios_isin_mm' )
.fields(
new Field( 'portfolios_isin_mm.account_id' ),
new Field( 'portfolios_isin_mm.user_id' ),
new Field( 'portfolios_isin_mm.uid_foreign' )
new Field( 'securities.issuer_name' ),
new Field( 'portfolios_isin_mm.isin' ),
new Field( 'portfolios_isin_mm.mic' ),
)
.leftJoin( 'portfolios_isin', 'portfolios_isin.id', '=', 'portfolios_isin_mm.uid_foreign' )
.leftJoin( 'securities', 'securities.isin', '=', 'portfolios_isin_mm.isin AND (securities.mic = portfolios_isin_mm.mic)' );
//.leftJoin( 'securities', 'securities.isin', '=', 'portfolios_isin_mm.isin' );
I'm getting an error. Debugging the error shows me:
{ Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.`mic)`' at line 1
at Query.Sequence._packetToError (/home/myproject/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
at Query.ErrorPacket (/home/myproject/node_modules/mysql/lib/protocol/sequences/Query.js:77:18)
at Protocol._parsePacket (/home/myproject/node_modules/mysql/lib/protocol/Protocol.js:278:23)
at Parser.write (/home/myproject/node_modules/mysql/lib/protocol/Parser.js:76:12)
at Protocol.write (/home/myproject/node_modules/mysql/lib/protocol/Protocol.js:38:16)
at Socket.<anonymous> (/home/myproject/node_modules/mysql/lib/Connection.js:91:28)
at Socket.<anonymous> (/home/myproject/node_modules/mysql/lib/Connection.js:502:10)
at Socket.emit (events.js:182:13)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:264:11)
at Socket.Readable.push (_stream_readable.js:219:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
--------------------
at Protocol._enqueue (/home/myproject/node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Connection.query (/home/myproject/node_modules/mysql/lib/Connection.js:200:25)
at /home/myproject/node_modules/knex/lib/dialects/mysql/index.js:152:18
at Promise._execute (/home/myproject/node_modules/bluebird/js/release/debuggability.js:313:9)
at Promise._resolveFromExecutor (/home/myproject/node_modules/bluebird/js/release/promise.js:483:18)
at new Promise (/home/myproject/node_modules/bluebird/js/release/promise.js:79:10)
at Client_MySQL._query (/home/myproject/node_modules/knex/lib/dialects/mysql/index.js:146:12)
at Client_MySQL.query (/home/myproject/node_modules/knex/lib/client.js:197:17)
at Runner.<anonymous> (/home/myproject/node_modules/knex/lib/runner.js:146:36)
at Runner.tryCatcher (/home/myproject/node_modules/bluebird/js/release/util.js:16:23)
at Runner.query (/home/myproject/node_modules/bluebird/js/release/method.js:15:34)
at /home/myproject/node_modules/knex/lib/runner.js:65:21
at tryCatcher (/home/myproject/node_modules/bluebird/js/release/util.js:16:23)
at /home/myproject/node_modules/bluebird/js/release/using.js:185:26
at tryCatcher (/home/myproject/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/home/myproject/node_modules/bluebird/js/release/promise.js:512:31)
code: 'ER_PARSE_ERROR',
errno: 1064,
sqlMessage:
'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.`mic)`' at line 1',
sqlState: '42000',
index: 0,
sql:
'select count(`portfolios_isin_mm`.`id`) as `cnt` from `portfolios_isin_mm` left join `portfolios_isin` on `portfolios_isin`.`id` = `portfolios_isin_mm`.`uid_foreign` left join `securities` on `securities`.`isin` = `portfolios_isin_mm`.`isin AND (securities`.`mic = portfolios_isin_mm`.`mic)`' }
... with the php libraries it was working just fine:
->leftJoin( 'securities', 'securities.isin', '=', 'portfolios_isin_mm.isin AND (securities.mic = portfolios_isin_mm.mic)' )
Supposedly I can quote 'The only way to do this at the moment is to create a VIEW that composes that join then you can select from that view. The readTable (https://editor.datatables.net/docs/1.8.1/nodejs/classes/editor.editor.html#readtable) method can be used to read information from the view while still updating to the host table.'
How can I get the complex left join to work in node.js as well (using a VIEW that composes that join (using knex))?
... I'm using $ node -v ... v10.15.0 and "datatables.net-editor-server": "^1.8.1"
javascript node.js datatables knex.js
I'm using the node.js datatable editor library. When trying to do a complex left join 'portfolios_isin_mm.isin AND (securities.mic = portfolios_isin_mm.mic)' ... like this:
let editor = new Editor( db, 'portfolios_isin_mm' )
.fields(
new Field( 'portfolios_isin_mm.account_id' ),
new Field( 'portfolios_isin_mm.user_id' ),
new Field( 'portfolios_isin_mm.uid_foreign' )
new Field( 'securities.issuer_name' ),
new Field( 'portfolios_isin_mm.isin' ),
new Field( 'portfolios_isin_mm.mic' ),
)
.leftJoin( 'portfolios_isin', 'portfolios_isin.id', '=', 'portfolios_isin_mm.uid_foreign' )
.leftJoin( 'securities', 'securities.isin', '=', 'portfolios_isin_mm.isin AND (securities.mic = portfolios_isin_mm.mic)' );
//.leftJoin( 'securities', 'securities.isin', '=', 'portfolios_isin_mm.isin' );
I'm getting an error. Debugging the error shows me:
{ Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.`mic)`' at line 1
at Query.Sequence._packetToError (/home/myproject/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
at Query.ErrorPacket (/home/myproject/node_modules/mysql/lib/protocol/sequences/Query.js:77:18)
at Protocol._parsePacket (/home/myproject/node_modules/mysql/lib/protocol/Protocol.js:278:23)
at Parser.write (/home/myproject/node_modules/mysql/lib/protocol/Parser.js:76:12)
at Protocol.write (/home/myproject/node_modules/mysql/lib/protocol/Protocol.js:38:16)
at Socket.<anonymous> (/home/myproject/node_modules/mysql/lib/Connection.js:91:28)
at Socket.<anonymous> (/home/myproject/node_modules/mysql/lib/Connection.js:502:10)
at Socket.emit (events.js:182:13)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:264:11)
at Socket.Readable.push (_stream_readable.js:219:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
--------------------
at Protocol._enqueue (/home/myproject/node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Connection.query (/home/myproject/node_modules/mysql/lib/Connection.js:200:25)
at /home/myproject/node_modules/knex/lib/dialects/mysql/index.js:152:18
at Promise._execute (/home/myproject/node_modules/bluebird/js/release/debuggability.js:313:9)
at Promise._resolveFromExecutor (/home/myproject/node_modules/bluebird/js/release/promise.js:483:18)
at new Promise (/home/myproject/node_modules/bluebird/js/release/promise.js:79:10)
at Client_MySQL._query (/home/myproject/node_modules/knex/lib/dialects/mysql/index.js:146:12)
at Client_MySQL.query (/home/myproject/node_modules/knex/lib/client.js:197:17)
at Runner.<anonymous> (/home/myproject/node_modules/knex/lib/runner.js:146:36)
at Runner.tryCatcher (/home/myproject/node_modules/bluebird/js/release/util.js:16:23)
at Runner.query (/home/myproject/node_modules/bluebird/js/release/method.js:15:34)
at /home/myproject/node_modules/knex/lib/runner.js:65:21
at tryCatcher (/home/myproject/node_modules/bluebird/js/release/util.js:16:23)
at /home/myproject/node_modules/bluebird/js/release/using.js:185:26
at tryCatcher (/home/myproject/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/home/myproject/node_modules/bluebird/js/release/promise.js:512:31)
code: 'ER_PARSE_ERROR',
errno: 1064,
sqlMessage:
'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.`mic)`' at line 1',
sqlState: '42000',
index: 0,
sql:
'select count(`portfolios_isin_mm`.`id`) as `cnt` from `portfolios_isin_mm` left join `portfolios_isin` on `portfolios_isin`.`id` = `portfolios_isin_mm`.`uid_foreign` left join `securities` on `securities`.`isin` = `portfolios_isin_mm`.`isin AND (securities`.`mic = portfolios_isin_mm`.`mic)`' }
... with the php libraries it was working just fine:
->leftJoin( 'securities', 'securities.isin', '=', 'portfolios_isin_mm.isin AND (securities.mic = portfolios_isin_mm.mic)' )
Supposedly I can quote 'The only way to do this at the moment is to create a VIEW that composes that join then you can select from that view. The readTable (https://editor.datatables.net/docs/1.8.1/nodejs/classes/editor.editor.html#readtable) method can be used to read information from the view while still updating to the host table.'
How can I get the complex left join to work in node.js as well (using a VIEW that composes that join (using knex))?
... I'm using $ node -v ... v10.15.0 and "datatables.net-editor-server": "^1.8.1"
javascript node.js datatables knex.js
javascript node.js datatables knex.js
edited Jan 3 at 11:11
Philipp M
asked Jan 3 at 11:00
Philipp MPhilipp M
8611929
8611929
This ought to work fine. But what I noticed was that there are some syntax errors in the generated sql query:
– Olantobi
Jan 3 at 11:25
Yes. But how to solve it to make it work?
– Philipp M
Jan 3 at 11:48
add a comment |
This ought to work fine. But what I noticed was that there are some syntax errors in the generated sql query:
– Olantobi
Jan 3 at 11:25
Yes. But how to solve it to make it work?
– Philipp M
Jan 3 at 11:48
This ought to work fine. But what I noticed was that there are some syntax errors in the generated sql query:
– Olantobi
Jan 3 at 11:25
This ought to work fine. But what I noticed was that there are some syntax errors in the generated sql query:
– Olantobi
Jan 3 at 11:25
Yes. But how to solve it to make it work?
– Philipp M
Jan 3 at 11:48
Yes. But how to solve it to make it work?
– Philipp M
Jan 3 at 11:48
add a comment |
1 Answer
1
active
oldest
votes
You have a syntax error in the last leftjoin.
.leftJoin( 'securities', 'securities.isin', '=', 'portfolios_isin_mm.isin AND (securities.mic = portfolios_isin_mm.mic)' )
This is why a wrong SQL query was generated:
select count(`portfolios_isin_mm`.`id`) as `cnt` from `portfolios_isin_mm` left join `portfolios_isin` on `portfolios_isin`.`id` = `portfolios_isin_mm`.`uid_foreign` left join `securities` on `securities`.`isin` = `portfolios_isin_mm`.`isin AND (securities`.`mic = portfolios_isin_mm`.`mic)`'
Notice the incomplete quotes starting from: portfolios_isin_mm
.`isin
You should consider using andOn() to include the 'AND' in your query:
.leftJoin('securities', function() {
this.on('securities.isin', '=', 'portfolios_isin_mm.isin')
.andOn('securities.mic', '=', portfolios_isin_mm.mic')
})
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54021010%2fnode-js-datatables-editor-how-to-use-a-knex-view-that-composes-a-join%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have a syntax error in the last leftjoin.
.leftJoin( 'securities', 'securities.isin', '=', 'portfolios_isin_mm.isin AND (securities.mic = portfolios_isin_mm.mic)' )
This is why a wrong SQL query was generated:
select count(`portfolios_isin_mm`.`id`) as `cnt` from `portfolios_isin_mm` left join `portfolios_isin` on `portfolios_isin`.`id` = `portfolios_isin_mm`.`uid_foreign` left join `securities` on `securities`.`isin` = `portfolios_isin_mm`.`isin AND (securities`.`mic = portfolios_isin_mm`.`mic)`'
Notice the incomplete quotes starting from: portfolios_isin_mm
.`isin
You should consider using andOn() to include the 'AND' in your query:
.leftJoin('securities', function() {
this.on('securities.isin', '=', 'portfolios_isin_mm.isin')
.andOn('securities.mic', '=', portfolios_isin_mm.mic')
})
add a comment |
You have a syntax error in the last leftjoin.
.leftJoin( 'securities', 'securities.isin', '=', 'portfolios_isin_mm.isin AND (securities.mic = portfolios_isin_mm.mic)' )
This is why a wrong SQL query was generated:
select count(`portfolios_isin_mm`.`id`) as `cnt` from `portfolios_isin_mm` left join `portfolios_isin` on `portfolios_isin`.`id` = `portfolios_isin_mm`.`uid_foreign` left join `securities` on `securities`.`isin` = `portfolios_isin_mm`.`isin AND (securities`.`mic = portfolios_isin_mm`.`mic)`'
Notice the incomplete quotes starting from: portfolios_isin_mm
.`isin
You should consider using andOn() to include the 'AND' in your query:
.leftJoin('securities', function() {
this.on('securities.isin', '=', 'portfolios_isin_mm.isin')
.andOn('securities.mic', '=', portfolios_isin_mm.mic')
})
add a comment |
You have a syntax error in the last leftjoin.
.leftJoin( 'securities', 'securities.isin', '=', 'portfolios_isin_mm.isin AND (securities.mic = portfolios_isin_mm.mic)' )
This is why a wrong SQL query was generated:
select count(`portfolios_isin_mm`.`id`) as `cnt` from `portfolios_isin_mm` left join `portfolios_isin` on `portfolios_isin`.`id` = `portfolios_isin_mm`.`uid_foreign` left join `securities` on `securities`.`isin` = `portfolios_isin_mm`.`isin AND (securities`.`mic = portfolios_isin_mm`.`mic)`'
Notice the incomplete quotes starting from: portfolios_isin_mm
.`isin
You should consider using andOn() to include the 'AND' in your query:
.leftJoin('securities', function() {
this.on('securities.isin', '=', 'portfolios_isin_mm.isin')
.andOn('securities.mic', '=', portfolios_isin_mm.mic')
})
You have a syntax error in the last leftjoin.
.leftJoin( 'securities', 'securities.isin', '=', 'portfolios_isin_mm.isin AND (securities.mic = portfolios_isin_mm.mic)' )
This is why a wrong SQL query was generated:
select count(`portfolios_isin_mm`.`id`) as `cnt` from `portfolios_isin_mm` left join `portfolios_isin` on `portfolios_isin`.`id` = `portfolios_isin_mm`.`uid_foreign` left join `securities` on `securities`.`isin` = `portfolios_isin_mm`.`isin AND (securities`.`mic = portfolios_isin_mm`.`mic)`'
Notice the incomplete quotes starting from: portfolios_isin_mm
.`isin
You should consider using andOn() to include the 'AND' in your query:
.leftJoin('securities', function() {
this.on('securities.isin', '=', 'portfolios_isin_mm.isin')
.andOn('securities.mic', '=', portfolios_isin_mm.mic')
})
answered Jan 3 at 12:02
OlantobiOlantobi
6141714
6141714
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54021010%2fnode-js-datatables-editor-how-to-use-a-knex-view-that-composes-a-join%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
This ought to work fine. But what I noticed was that there are some syntax errors in the generated sql query:
– Olantobi
Jan 3 at 11:25
Yes. But how to solve it to make it work?
– Philipp M
Jan 3 at 11:48