1

我使用 playframework2+slick2.0

我的数据模型:

class Page(tag:Tag) extends Table[(Int,Int, String,String,String, Option[String], Option[String])](tag, "Page"){
  def id=column[Int]("ID", O.PrimaryKey)
  def subId=column[Int]("subject")
  def title=column[String]("Title", O.NotNull)
  def describe=column[String]("Describe")
  def profile=column[String]("Profile")
  def icon=column[Option[String]]("icon")
  def resId=column[String]("Picture")
  def * = (id, subId,title, describe, profile,icon, resId.?)
  def page_sub=foreignKey("PA_SU_FK", subId, subject)(_.id)
  def page_res=foreignKey("PA_RE_FK", resId, resource)(_.link)

}
    val page=TableQuery[Page]

class Resource(tag:Tag) extends Table[(String, String, Boolean)](tag, "Resource"){
  def link=column[String]("Link", O.PrimaryKey)
  def rtype=column[String]("class")
  def local=column[Boolean]("local")
  def * = (link, rtype,local)
}
val resource=TableQuery[Resource]

我想使用过滤器获取一行,并获取资源对象表单页面:

我的代码是这样的:

 val item=page.filter(_.id===id.toInt).first()(rs.dbSession)

这只是获取页面真实对象,我要获取对应的资源对象,如何通过过滤器获取呢?

4

1 回答 1

1

您可以使用理解:

 val pageWithResouce = (for {
   p <- page if (p.id === id.toInt)
   r <- resource if (p.resId === r.link)
  } yield { (p, r) })list
于 2014-04-16T14:04:57.787 回答