Reputation: 1081
I have the following Slick action that updates all dates in year 2016 excluding Saturdays and Sundays
val action = dates.filter( d => d.year === 2016 &&
d.weekDay != "Sat" && d.weekDay != "Sun").map(x => (x.isHoliday)).update(0)
Await.result(db.run(action), Duration.Inf).value
val sql = action.statements.head
println(sql)
Problem is that the update doesn't work as intended, the sql prints
update `dates` set `is_holiday` = ? where ((`dates`.`year` = 2016) and true) and true
when it should print
update `dates` set `is_holiday` = ? where `dates`.`year` = 2016
and `dates`.`week_day` != 'Sat' and `dates`.`week_day` != 'Sun'
What is wrong with this statement?
Upvotes: 0
Views: 45
Reputation: 18187
I believe that you are accidentally using the scala !=
operator instead of the Slick =!=
function. Try this:
val action = dates.filter(d => d.year === 2016 && d.weekDay =!= "Sat" && d.weekDay =!= "Sun").map(x => (x.isHoliday)).update(0)
You could also try this:
val weekendDays = Set("Sat", "Sun")
val action = dates.filter(d => d.year === 2016 && !d.weekDay.inSet(weekendDays))
Upvotes: 2