문제

This is a sample code from play2's built-in's zentasks:

object Project {

  // -- Parsers

  /**
   * Parse a Project from a ResultSet
   */
  val simple = {
    get[Pk[Long]]("project.id") ~
    get[String]("project.folder") ~
    get[String]("project.name") map {
      case id~folder~name => Project(id, folder, name)
    }
  }
}

Please notice the field keys: project.id, project.folder, project.name.

What does the project part mean? Where is it come from?

Look at the query method:

  def findById(id: Long): Option[Project] = {
    DB.withConnection { implicit connection =>
      SQL("select * from project where id = {id}").on(
        'id -> id
      ).as(Project.simple.singleOpt)
    }
  }

The SQL is select * from project ..., the result should be:

    id    |    folder    |   name

Not:

    project.id    |    project.folder    |    project.name

Why we should specify the keys as project.???, but not field name directly?

How play2 use the project. part?

도움이 되었습니까?

해결책

As per the code available in here, Anorm Parser uses the string provided to retrieve the given column.

As it gets some metadata, it requires teh full scope of the field (table + name) to work.

다른 팁

IMHO it's just DB alias.

select id, folder, name from project

is the same as

select project.id, project.folder, project.name from project

or even

select p.id, p.folder, p.name from project p
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top