2015-11-04 59 views
1

我有一个简单的更新,试图更新特定行的两列。下面是我做的:(我使用Scala的2.11.7)油滑3.0.0使用更新时的警告

val update = 
    (id: Long, state: MyState) => 
    myTable.filter(_.id === id) 
     .map(tbl =>(tbl.name, tbl.updateDate)) 
     .update(state.name, DateTime.now(DateTimeZone.UTC)) 

这里是我的编译器告诉我:

[warn] /Users/joe/vpp-projects/app/my/project/services/database/MySchema.scala:40: Adapting argument list by creating a 2-tuple: this may not be what you want. 
[warn]   signature: UpdateActionExtensionMethodsImpl.update(value: T): JdbcActionComponent.this.DriverAction[Int,slick.dbio.NoStream,slick.dbio.Effect.Write] 
[warn] given arguments: state.name, DateTime.now(DateTimeZone.UTC) 
[warn] after adaptation: UpdateActionExtensionMethodsImpl.update((state.name, DateTime.now(DateTimeZone.UTC)): (String, org.joda.time.DateTime)) 
[warn]   .update(state.name, DateTime.now(DateTimeZone.UTC)) 
[warn]   

    ^

任何线索,这里发生了什么?我没有得到警告对我有任何用处,所以我可以摆脱它!

回答

3

update需要Tuple - Scala有一个功能,将多个参数的方法调用转换成一个元组,如果没有方法,它采用了多个参数:

def anExample(value: (Int, Int, String)): Int = value._3.length 

// This is how it is properly called 
anExample((1, 2, "hi")) 

// But this also works 
anExample(1, 2, "hi") 

您可以:

  • 更新您的通话

    // Note the added tuple parenthesis 
    .update((state.name, DateTime.now(DateTimeZone.UTC))) 
    
  • 添加-Yno-adapted-argsscalacOptions完全去除警告:

    // If using SBT 
    scalacOptions in Compile += "-Yno-adapted-args"