2016-07-03 16 views
2

私はPhantom 1.26.6を使用しています。phantom-dslの行内の複数のフィールドを更新するにはどうすればよいですか?

// id is the primary key 
case class Motorcycle(id:String, model:String, made:String, capacity:Int) 

既にカサンドラに存在オートバイのインスタンスを与え、私は 、製、モデルの値を更新する能力を望みます。

// The following does not compile. 
update.where(_.id.eqs(bike.id)).modify(_.model.setTo(bike.model)) 
.modify(_.make.setTo(bike.make)) 
.modify(_.capacity.setTo(bike.capacity)) 


// The following works. 
val updateQuery = update.where(_.id.eqs(bike.id)) 

for { 
    _ <- updateQuery.modify(_.model.setTo(bike.model)).future() 
    _ <- updateQuery.modify(_.make.setTo(bike.made)).future() 
    result <- updateQuery.modify(_.capacity.setTo(bike.capacity)).future() 
    } yield (result) 

複数のフィールドを更新する方がいいかと思います。どのような援助のため、事前に

ありがとう!

答えて

2

をシン

は、あなたがしなければならないのは、チェーン複数の更新文にand演算子を使用することです。これにより、すべてのクエリが1つのクエリで実行されます。

val updateQuery = update.where(_.id eqs bike.id) 
    .modify(_model setTo bike.model) 
    .and(_.make setTo bike.made) 
    .and(_.capacity setTo bike.capacity) 
    .future() 
関連する問題