Question

Is there a bulkUpdate method similar to bulkDelete_!! in mapper so that i can update records in underlying table ?

Was it helpful?

Solution

As per my knowledge , Unfortunately in order to perform bulk update ( based on some criteria ) we have to use sql query only. No method similar to bulkDelete_!! available for bulk Update.

For example:

def updateNameById (newName : String,  id : Long) = {  
    val updateString = "update MyModel set name = ? where id = ?"    
    DB.use(DefaultConnectionIdentifier) { conn =>
        DB.prepareStatement(updateString, conn) { stmt =>
              stmt.setString(1, newName)
              stmt.setLong(2, id)
              stmt.executeUpdate()
        }
    }
}

OTHER TIPS

No, there is no bulkUpdate in Mapper, you would have to do a findAll, edit the records and then do a .save on them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top