Is there a bulkUpdate method similar to bulkDelete_!! in mapper so that i can update records in underlying table ?
Asked
Active
Viewed 221 times
2 Answers
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
-
but that will be querying the database twice, won't it ? ( Once for findAll and onceagain for save ) – vkantiya Nov 09 '11 at 04:45
-
That is correct. To avoid that you would have to use a custom sql, like @vkantiya wrote – fmpwizard Nov 09 '11 at 17:56