Created
November 3, 2021 14:10
-
-
Save nakamura-to/3cc0d3b5889cfe5dd2edf1e4f59c397c to your computer and use it in GitHub Desktop.
Komapperでエンティティの関連づけを行うAPIの例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val d = Dept.meta | |
val e = Emp.meta | |
val query = SqlDsl.from(d).innerJoin(e){ d.id eq e.deptId }.associate(d, e) | |
val aggregate = db.runQuery { query } | |
val map: Map<Dept, Set<Emp>> = aggregate.oneToMany(d, e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// associateを呼んだ分だけ実行結果から関連づけされたMapを取得できる | |
val d = Dept.meta | |
val e = Emp.meta | |
val a = Address.meta | |
val query = SqlDsl.from(d) | |
.innerJoin(e){ d.id eq e.deptId } | |
.innerJoin(a){ a.id eq e.addressId } | |
.associate(d, e) | |
.associate(e, a) | |
val aggregate = db.runQuery { query } | |
val map1: Map<Dept, Set<Emp>> = aggregate.oneToMany(d, e) | |
val map2: Map<Emp, Address?> = aggregate.oneToOne(e, a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment