mirror of
https://github.com/knex/knex.git
synced 2026-01-03 18:48:37 +00:00
Fix #441, raw in first argument of join
This commit is contained in:
parent
393769b80d
commit
886634eb02
@ -104,9 +104,7 @@ QueryBuilder.prototype.join = function(table, first, operator, second) {
|
||||
}
|
||||
var join;
|
||||
var joinType = this._joinType();
|
||||
if (table instanceof Raw) {
|
||||
join = new JoinClause(table, 'raw');
|
||||
} else if (_.isFunction(first)) {
|
||||
if (_.isFunction(first)) {
|
||||
join = new JoinClause(table, joinType);
|
||||
first.call(join, join);
|
||||
} else if (joinType === 'raw') {
|
||||
|
||||
@ -1741,19 +1741,6 @@ module.exports = function(qb, clientName, aliasName) {
|
||||
});
|
||||
});
|
||||
|
||||
it('accepts a knex.raw for arbitrary join clauses', function() {
|
||||
testsql(qb().select('*').from('accounts').join(raw('natural full join table1')).where('id', 1), {
|
||||
mysql: {
|
||||
sql: 'select * from `accounts` natural full join table1 where `id` = ?',
|
||||
bindings: [1]
|
||||
},
|
||||
default: {
|
||||
sql: 'select * from "accounts" natural full join table1 where "id" = ?',
|
||||
bindings: [1]
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('allows sub-query function on insert, #427', function() {
|
||||
testsql(qb().into('votes').insert(function() {
|
||||
this.select('*').from('votes').where('id', 99);
|
||||
@ -1797,6 +1784,32 @@ module.exports = function(qb, clientName, aliasName) {
|
||||
});
|
||||
});
|
||||
|
||||
it('allow for raw values in join, #441', function() {
|
||||
testsql(qb()
|
||||
.select('A.nid AS id')
|
||||
.from(raw('nidmap2 AS A'))
|
||||
.innerJoin(
|
||||
raw([
|
||||
'SELECT MIN(nid) AS location_id',
|
||||
'FROM nidmap2',
|
||||
].join(' ')).wrap('(', ') AS B'),
|
||||
'A.x', '=', 'B.x'
|
||||
), {
|
||||
mysql: {
|
||||
sql: 'select `A`.`nid` as `id` from nidmap2 AS A inner join (SELECT MIN(nid) AS location_id FROM nidmap2) AS B on `A`.`x` = `B`.`x`',
|
||||
bindings: []
|
||||
},
|
||||
oracle: {
|
||||
sql: 'select "A"."nid" "id" from nidmap2 AS A inner join (SELECT MIN(nid) AS location_id FROM nidmap2) AS B on "A"."x" = "B"."x"',
|
||||
bindings: []
|
||||
},
|
||||
default: {
|
||||
sql: 'select "A"."nid" as "id" from nidmap2 AS A inner join (SELECT MIN(nid) AS location_id FROM nidmap2) AS B on "A"."x" = "B"."x"',
|
||||
bindings: []
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user