var newitem := Question{}
  init {
    newitem.answers := [Answer{}];
  }
  form {
    label("Question: ") { input( newitem.question)}
    for (a in newitem.answers) {
      label("Answer: ") { input( a.answer )}
    }
    submit action{
      newitem.save();
     }{ "Add question" }
  }

above did not save answers, workaround:

  var newitem := Question{}
  var answers := [Answer{}]

edit: seems related to the inverse annotation

page root {
  var newitem := Question{ answers := [Answer{}] }
  form {
    input( newitem.question )
    for (a in newitem.answers) {
      input( a.answer )
    }
    submit action{ 
      newitem.save(); 
    }{ "Add" }
  }
  for( q: Question ){
      output( "Question: " + q.question )
      for ( a: Answer in q.answers ) {
        h6 { "Answer: " output( a.answer )}
      }
  }
}
entity Question {
  question: String
  answers: [Answer]
}
entity Answer {
  question: Question (inverse=answers) // works without inverse
  answer : String 
}
Submitted by Danny Groenewegen on 31 March 2021 at 15:06

Log in to post comments