I'm curious how I get the inserted object back. I'd like to return the constructed model object in my create
API route in Play.
So far I have something like:
def create(username: String, email: String, password:String)(implicit database: Database): Option[FailureResult] = {
database withSession {
implicit session => {
val affectedRows = users += new User(username=username, email=email, password=password)
onlyIf(affectedRows != 1){ UnexpectedErrorResult("Unexpected Error: User was not created") }
}
}
The +=
operator only returns the affected rows. Is there a way to get the object back without doing another find?