49

How do you update multiple columns using Slick Lifted Embedding ? This document doesn't say much.

I expected it to be something like this

Query(AbilitiesTable).filter((ab: AbilitiesTable.type) => ab.id === ability_id).map((ab: AbilitiesTable.type) => (ab.verb, ab.subject)).update("edit", "doc")
expert
  • 29,290
  • 30
  • 110
  • 214

2 Answers2

78

With recent versions of Slick, this way of writing it works:

Users.filter(_.id === filterId)
     .map(x => (x.name, x.age))
     .update(("john", 99))

Be careful to remember the extra parentheses if you are updating more than one property otherwise you might get a compiler warning.

nemoo
  • 3,269
  • 4
  • 38
  • 51
75

I figured it out. It should be like this

val map = Query(AbilitiesTable)
  .filter(_.id === ability_id)
  .map(ab => ab.verb ~ ab.context)

map.update(("", ""))

Typesafe, why your documentation is so bad ? I have to Google pretty much every silly thing or dig through unit-tests for hours. Please improve it. Thanks.

EECOLOR
  • 11,184
  • 3
  • 41
  • 75
expert
  • 29,290
  • 30
  • 110
  • 214
  • 10
    Note this only works with updateable ResultSets, which require that you include the ID. If you try to use this without including the ID field in the built query, it will fail. – BeepDog Jun 13 '13 at 22:04
  • Sorry...but what is `AbilitiesTable`? Is this that `TableQuery` object? The class like this: `class CompanyTable(tag: Tag) extends Table[Company]`? – windweller Jul 04 '14 at 20:50