Skip to content

Instantly share code, notes, and snippets.

@tsukaby
Created March 22, 2015 09:53
Show Gist options
  • Save tsukaby/957c6d43421fb96ec93f to your computer and use it in GitHub Desktop.
Save tsukaby/957c6d43421fb96ec93f to your computer and use it in GitHub Desktop.
Skinny-ORM. Eager loading (Bad example). #includes
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
}
}
)
}
@tsukaby
Copy link
Author

tsukaby commented Mar 22, 2015

memo : このEager loadingはダメな方法です。
こちらを参考にしてください。
https://github.com/tsukaby/skinny-orm-example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment