I am using play-slick for my scala Play! dummy rest API.
So, I have to fetch records from multiple tables. But, they are interdependent, i.e.
Table_1 Table_2
id1 id2
id2
To fetch a record from Table_2 I have to fetch a record from Table_1 and then using id2 fetch from Table_2.
My controller:
def getEntity(id : Long) = Action.async {
table1DAO.findById(id) map { t1 =>
t1 map { t1Entity =>
table2DAO.findById(t1Entity.id2) map { t2 =>
t2 map { t2Entity =>
Ok(Json.toJson(CombiningClass(t1Entity, t2Entity)))
} getOrElse { Ok(Json.toJson(t1Entity)) }
}
} getOrElse { NoContent }
}
}
After compilation, I get:
[error] DummyController.scala:17: overloaded method value async with alternatives:
[error] [A](bodyParser: play.api.mvc.BodyParser[A])(block: play.api.mvc.Request[A] => scala.concurrent.Future[play.api.mvc.Result])play.api.mvc.Action[A] <and>
[error] (block: play.api.mvc.Request[play.api.mvc.AnyContent] => scala.concurrent.Future[play.api.mvc.Result])play.api.mvc.Action[play.api.mvc.AnyContent] <and>
[error] (block: => scala.concurrent.Future[play.api.mvc.Result])play.api.mvc.Action[play.api.mvc.AnyContent]
[error] cannot be applied to (scala.concurrent.Future[Object])
[error] def getEntity(id : Long) = Action.async {
[error] ^
[error] one error found
Here's my DAO method:
def findById(id : Long): Future[Option[A]] = {
db.run(tableQ.filter(_.id === id).result.headOption)
}
PS: I'm very new to functional paradigm and scala, so if you can, pardon my ignorance.