Skip to content

Commit 4493f78

Browse files
committed
Merge pull request brianc#38 from esessoms/chainable-joins
should be able to chain leftJoin
2 parents 479f28d + 12fb2dc commit 4493f78

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

lib/node/join.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ var JoinNode = module.exports = require(__dirname).define({
1111
},
1212
join: function(other) {
1313
return new JoinNode('INNER', this, other);
14+
},
15+
leftJoin: function(other) {
16+
return new JoinNode('LEFT', this, other);
1417
}
1518
});

test/postgres/join-tests.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ Harness.test({
2525
pg : 'SELECT "user"."name", "post"."content" FROM "user" LEFT JOIN "post" ON ("user"."id" = "post"."userId")'
2626
});
2727

28+
Harness.test({
29+
query : user
30+
.select(user.name, post.content)
31+
.from(
32+
user
33+
.leftJoin(post).on(user.id.equals(post.userId))
34+
.leftJoin(comment).on(post.id.equals(comment.postId))
35+
),
36+
pg : 'SELECT "user"."name", "post"."content" FROM "user" LEFT JOIN "post" ON ("user"."id" = "post"."userId")' +
37+
' LEFT JOIN "comment" ON ("post"."id" = "comment"."postId")'
38+
});
39+
2840
Harness.test({
2941
query : user
3042
.select(user.name, post.content)

0 commit comments

Comments
 (0)