Created
March 22, 2015 09:53
-
-
Save tsukaby/957c6d43421fb96ec93f to your computer and use it in GitHub Desktop.
Skinny-ORM. Eager loading (Bad example). #includes
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
object Person extends SkinnyCRUDMapper[Person] { | |
override def defaultAlias = createAlias("person") | |
override def extract(rs: WrappedResultSet, n: ResultName[Person]): Person = new Person( | |
id = rs.get(n.id), | |
name = rs.get(n.name) | |
) | |
val companyRef = | |
belongsTo[Company](Company, (p, c) => p.copy(company = c)) | |
.includes[Company]( | |
merge = (persons, companies) => persons.map { p => | |
p.company match { | |
case Some(x) => | |
p.copy(company = Some(x.copy(companyType = x.companyTypeId.flatMap(CompanyType.findById)))) | |
case None => p | |
} | |
} | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
memo : このEager loadingはダメな方法です。
こちらを参考にしてください。
https://github.com/tsukaby/skinny-orm-example