Created
March 3, 2017 01:46
-
-
Save j5ik2o/6ecc597f69373ecb7d4757e9c840878e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
case class Item( | |
id: Option[Long], | |
code: String, | |
name: String, | |
url: String, | |
imageUrl: String, | |
price: Int, | |
createAt: DateTime, | |
updateAt: DateTime, | |
users: Seq[User] = Seq.empty | |
) | |
object Item extends SkinnyCRUDMapper[Item] { | |
override def tableName: String = "items" | |
override def defaultAlias: Alias[Item] = createAlias("i") | |
// snip | |
} | |
case class ItemUser(id: Option[Long], | |
itemId: Long, | |
userId: Long, | |
`type`: String, | |
createAt: DateTime, | |
updateAt: DateTime | |
) extends SkinnyJoinTable[ItemUser] { | |
override def defaultAlias: Alias[ItemUser] = createAlias("iu") | |
} | |
case class User( | |
id: Option[Long] = None, | |
name: String, | |
email: String, | |
password: String, | |
createAt: DateTime = DateTime.now(), | |
updateAt: DateTime = DateTime.now(), | |
items: Seq[Item] = Seq.empty | |
) | |
object User extends SkinnyCRUDMapper[User] { | |
override def tableName = "users" | |
override def defaultAlias: Alias[User] = createAlias("u") | |
val allItems: HasManyAssociation[User] = hasManyThrough[Item]( | |
through = ItemUser, | |
many = Item, | |
merge = (user, items) => user.copy(items = items) | |
) | |
// `type`がwantの場合のみのレコードとジョインしたい | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment