Skip to content

Commit 0e2b9b6

Browse files
authored
Merge pull request #2180 from david-lebl-adastra/main
Add test for issue #2144
2 parents e0a3105 + beba12d commit 0e2b9b6

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

modules/core/src/test/scala/doobie/util/ReadSuite.scala

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,37 @@ class ReadSuite extends munit.FunSuite with ReadSuitePlatform {
168168
assertEquals(o2, List(None))
169169
}
170170

171+
test("Read should read correct columns for instances with Option (None) with left join between two tables") {
172+
import doobie.implicits.*
173+
174+
case class Foo(foo_key: Int, b: String)
175+
case class Bar(bar_key: Int, d: Option[String])
176+
177+
val result: List[(Foo, Option[Bar])] = (for {
178+
_ <- sql"drop table if exists foo".update.run
179+
_ <- sql"drop table if exists bar".update.run
180+
_ <- sql"create table foo(foo_key int, foo_value varchar not null)".update.run
181+
_ <- sql"create table bar(bar_key int, foo_key int, bar_value varchar)".update.run
182+
183+
_ <- sql"insert into foo values (1, 'a'), (2, 'b'), (3, 'c')".update.run
184+
_ <- sql"insert into bar values (1, 1, 'c'), (2, 2, null)".update.run
185+
186+
q <-
187+
sql"select f.foo_key, f.foo_value, b.bar_key, b.bar_value from foo f left join bar b on f.foo_key = b.foo_key"
188+
.query[(Foo, Option[Bar])].to[List]
189+
} yield q)
190+
.transact(xa)
191+
.unsafeRunSync()
192+
193+
assertEquals(
194+
result,
195+
List(
196+
(Foo(1, "a"), Some(Bar(1, Some("c")))),
197+
(Foo(2, "b"), Some(Bar(2, None))),
198+
(Foo(3, "c"), None)
199+
))
200+
}
201+
171202
test("Read should read correct columns for instances with Option (Some)") {
172203
import doobie.implicits.*
173204

0 commit comments

Comments
 (0)