Is it somehow possible to overcome the “Cannot write to a computed field” constraint?
We would like to achieve that if a chapter contains a masterChapter
, the chapter
title
will be computed from masterChapter.title
. But if it doesn’t contain a masterChapter
, it should use the chapter
title
. For that, we would like to be able to write/create chapter as part of chapters, but this is currently throwing a “Cannot write to a computed field”.
Collection.byName("Document")!.update({
computed_fields: {
chapters: {
body: "doc => {
doc.chapters.map((chapter) => {
if(chapter.masterChapter != null) {
{
title: chapter.masterChapter.title,
masterChapter: chapter.masterChapter
}
} else {
chapter
}
})
}",
signature: "Array"
}
}
})
Example document structure
Document.create({
chapters: [
{
title: "This title should be seen"
},
{
title: "This title should never be seen!",
masterChapter: MasterChapter.byId("390327058219139280"),
},
]
})