Self-reference model
Models
const Self = Fractale.create("Self", {
self: Self,
value: String
});
Run
const { Self } = module.exports.get();
const instance_1 = new Self({ value: 'foo' });
const instance_2 = new Self({ self: { self: instance_1, value: 'bar' }, value: 'hello' });
_.test(instance_1.value, 'foo', 'Error on deep accessor variable name');
_.test(instance_2.self.value, 'bar', 'Error on self-reference accessor');
_.test(instance_2.self.self.value, 'foo', 'Error on double self-reference accessor');
_.test(instance_2.self.self.self, undefined, 'Error infinite self-reference accessor');
resolve(instance_2);
Results
{
"uuid": "9ad98dd3-6e65-41e0-a592-998c68aafe95",
"self": {
"uuid": "3365521f-4db8-4856-a5a2-5dacda8648ba",
"self": {
"uuid": "49e72f5e-faa3-4948-a162-3f4abdb792f6",
"value": "foo"
},
"value": "bar"
},
"value": "hello"
}
Last updated
Was this helpful?