Book Image

Mastering play framework for scala

By : Shiti Saxena
Book Image

Mastering play framework for scala

By: Shiti Saxena

Overview of this book

Table of Contents (21 chapters)
Mastering Play Framework for Scala
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Getting Started with Play
Index

Troubleshooting


The following section covers some common scenarios:

  • Anorm throws an error at the SqlMappingError runtime (too many rows when you're expecting a single one), even though the query resulted in expected behavior. It is an insert query using "on duplicate key update".

    This can happen when such a query is being executed using executeInsert. The executeInsert method should be used when we need to return an autogenerated key. If we are updating some fields through a duplicate key, it means that we do not actually need the key. We could use executeUpdate to add a check if one row has been updated. For example, we may want to update the wishlist table, which tracks what a user has wished for:

    DB.withConnection {
            implicit connection => {
    
      val updatedRows = SQL"""INSERT INTO wish_list (user_id, product_id, liked_at) VALUES ($userId,$productId,$likedAt)
        ON DUPLICATE KEY UPDATE liked_at=$likedAt, is_deleted=false """.executeUpdate()
    
      updatedRows == 1
      }
    }
  • Can we use multiple...