And a mapping which sets the Parents against the Child:
export function handleSetParents(): void {
let parent1 = Parent1.load('1')
parent1 = parent1 === null ? new Parent1('1') : parent1
parent1.save()
let parent2 = Parent2.load('2')
parent2 = parent2 === null ? new Parent2('2') : parent2
parent2.save()
let child = Child.load('3')
child = child === null ? new Child('3') : child
child.parent1 = parent1.id
child.parent2 = parent2.id
child.save()
}
We would expect to be able to test that the association is made when we call handleSetParents from a test:
// this test passes
test('derived fields associating the parent and child are created', () => {
handleSetParents()
assert.fieldEquals('Parent2', '2', 'children', `[3]`)
})
... however ...
// this fails with an error like: `... with message: unexpected null, wasm backtrace: ...`
test('derived fields associating the parent and child are created', () => {
handleSetParents()
assert.fieldEquals('Parent1', '1', 'children', `[3]`)
assert.fieldEquals('Parent2', '2', 'children', `[3]`)
})
Given the following schema:
And a mapping which sets the
Parents
against theChild
:We would expect to be able to test that the association is made when we call
handleSetParents
from a test:... however ...