4

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

vkantiya
  • 1,343
  • 1
  • 8
  • 20

2 Answers2

5

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()
        }
    }
}
vkantiya
  • 1,343
  • 1
  • 8
  • 20
1

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

fmpwizard
  • 2,758
  • 1
  • 22
  • 24