出于某种原因,在某些情况下,knex不会向查询添加左连接。我尝试用最少的代码重现bug,所以我尝试将knex用于内存中的sqlite3。
var knex = require('knex')({
client:'sqlite3',
connection: {
filename: ":memory:"
},
debug: true
});
var bookshelf = require('bookshelf')(knex);
var Conversation = bookshelf.Model.extend({
tableName: 'conversations',
});
Conversation
.where(qb => {
qb
.leftJoin('conversations_recipients', function () {
this.on('conversations_recipients.conversationId', 'conversations.id');
});
})
.fetch();
当我在控制台上检查调试消息时,我得到:
{ method: 'select',
options: {},
bindings: [ 1 ],
sql: 'select "conversations".* from "conversations" limit ?' }
左边的连接丢失了。有人知道这段代码有什么问题,我怎样才能包含所需的连接?
提前致谢。