How to update nested list table using framework activation
I have two objects Task
and Comment
. There Task
is a list Comment
. When I post a new comment for a specific task, how do I do it? Should I create a new comment first? If I create a new one Comment
, how can the database know that it belongs to any task?
Here are my enitities:
case class Task (
var title: String,
var description: String,
var estimate: Int,
var time_start: String,
var time_end: String,
var state: String,
var created_at: String,
var created_by: String,
var modified_at: String,
var modified_by: String,
var members: scala.collection.immutable.List[User],
var comments: scala.collection.immutable.List[Comment])
extends Entity
case class Comment (
var content: String,
var created_at: String,
var edited_at: String,
var last_comment: String)
extends Entity
I am using createTableForAllEntities
to create tables and the table is automatically created:
CREATE CACHED TABLE PUBLIC.TASKCOMMENTS(
OWNER VARCHAR(1000),
VALUE VARCHAR(45),
POS INTEGER
)
I think I need to update this nested list table, but how?
And this is what I found in the game tutorial:
When using duplicate data like this, the form values submitted by the browser should be named email [0], emails [1], emails [2], etc.
So, I think I should edit the json of the tasks this way, but how?
I first try to create a new comment and get it from the database. Then using
val toUpdate = new EntityMap[Task](oldT)
val oldComments = toUpdate.get(_.comments).getOrElse(List())
val newComments = oldComments :+ newC
toUpdate.put(_.comments)(newComments)
transactional(toUpdate.updateEntity(oldT.id))
He still can't update comments!
source to share
No one has answered this question yet
Check out similar questions: