Reputation: 5629
I have the following code:
def getContentComponents: Action[AnyContent] = Action.async {
contentComponentDTO.list().map(contentComponentsFuture =>
contentComponentsFuture.foreach(contentComponentFuture =>
contentComponentFuture.typeOf match {
case 5 =>
contentComponentDTO.getContentComponentText(contentComponentFuture.id.get).map(
text => contentComponentFuture.text = text.text
)
}
)
Ok(Json.toJson(contentComponentsFuture))
)
and get this error message while assigning a value:
Is there a way to solve this issue?
I thought about creating a copy but that would mean that I have do lots of other stuff later. It would be much easier for me if I could reassign the value.
thanks
Upvotes: 0
Views: 331
Reputation: 5629
Just found the solution ...
In model I have to define the Attributes as var
case class ContentComponentModel(
id: Option[Int] = None,
typeOf: Int,
name: String,
version: String,
reusable: Option[Boolean],
createdat: Date,
updatedat: Date,
deleted: Boolean,
processStepId: Int,
var text: Option[String],
Upvotes: 1
Reputation: 1108
Unfortunately this is not possible as contentComponentFuture.text
is an immutable property so you cannot change its value like that.
The only way to "change" the values of the job object is to actually create a totally new instance and discard the old one. This is standard practice when dealing with immutable objects.
Sorry for the bad news.
Upvotes: 1