2016-07-03 1 views
2

팬텀 1.26.6을 사용하고 있습니다. 팬텀 -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 연산자를 사용하는 것입니다 아성. 이렇게하면 모든 쿼리가 단일 쿼리로 실행됩니다.

val updateQuery = update.where(_.id eqs bike.id) 
    .modify(_model setTo bike.model) 
    .and(_.make setTo bike.made) 
    .and(_.capacity setTo bike.capacity) 
    .future() 
관련 문제