@@ -94,6 +94,15 @@ class QueryTests : XCTestCase {
9494 )
9595 }
9696
97+
98+ func test_join_compilesJoinClause_withNamespaces( ) {
99+ let query = users. join ( posts, on: posts [ userId] == users [ id] ) . select ( posts [ * ] , users [ * ] )
100+ AssertSQL (
101+ " SELECT \" posts \" .*, \" users \" .* FROM \" users \" INNER JOIN \" posts \" ON ( \" posts \" . \" user_id \" = \" users \" . \" id \" ) " ,
102+ query
103+ )
104+ }
105+
97106 func test_filter_compilesWhereClause( ) {
98107 AssertSQL ( " SELECT * FROM \" users \" WHERE ( \" admin \" = 1) " , users. filter ( admin == true ) )
99108 }
@@ -514,6 +523,34 @@ class QueryIntegrationTests : SQLiteTestCase {
514523 XCTAssertEqual ( Array ( expectedIDs. reversed ( ) ) , orderedIDs)
515524 }
516525
526+ func test_joinClause_withNamespaces( ) throws {
527+ let posts = Table ( " posts " )
528+ let userId = Expression < Int64 > ( " userId " )
529+ let postId = Expression < Int64 > ( " id " )
530+ let title = Expression < String > ( " title " )
531+ let content = Expression < String > ( " content " )
532+ try db. run ( posts. create { builder in
533+ builder. column ( postId)
534+ builder. column ( userId)
535+ builder. column ( title)
536+ builder. column ( content)
537+ builder. primaryKey ( postId)
538+ } )
539+ let alice = try db
. run ( users
. insert ( email
<- " [email protected] " ) ) 540+ let sally = try db
. run ( users
. insert ( email
<- " [email protected] " ) ) 541+ let postAlice = try db. run ( posts. insert ( userId <- alice, postId <- 1 , title <- " title1 " , content <- " content1 " ) )
542+ let postSally = try db. run ( posts. insert ( userId <- sally, postId <- 2 , title <- " title2 " , content <- " content2 " ) )
543+
544+ let query = users
545+ . join ( posts, on: posts [ userId] == users [ id] )
546+ . select ( posts [ * ] , users [ * ] )
547+ . order ( userId)
548+
549+ let ids = try db. prepare ( query) . map { $0 [ posts [ id] ] }
550+ XCTAssertEqual ( [ postAlice, postSally] , ids)
551+ }
552+
553+
517554 func test_no_such_column( ) throws {
518555 let doesNotExist = Expression < String > ( " doesNotExist " )
519556 try ! InsertUser ( " alice " )
0 commit comments