| Total Complexity | 2 |
| Complexity/F | 0 |
| Lines of Code | 32 |
| Function Count | 0 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import Field from "../Field"; |
||
| 2 | |||
| 3 | export default class MorphTo extends Field { |
||
| 4 | |||
| 5 | constructor(name) { |
||
| 6 | super(name); |
||
| 7 | } |
||
| 8 | |||
| 9 | get value() { |
||
| 10 | const name = this.$parent.snakeCaseClassName; |
||
| 11 | |||
| 12 | const type = this.$parent[`${name}_type`]; |
||
| 13 | const id = this.$parent[`${name}_id`]; |
||
| 14 | |||
| 15 | return Object.getPrototypeOf(globalThis.Store.classInstances[type]).constructor.find(id); |
||
| 16 | } |
||
| 17 | |||
| 18 | set _value(value) { |
||
| 19 | if (!Array.isArray(value)) { |
||
| 20 | value = [value]; |
||
| 21 | } |
||
| 22 | |||
| 23 | const name = this.$parent.snakeCaseClassName; |
||
| 24 | const type = `${name}_type`; |
||
| 25 | const id = `${name}_id`; |
||
| 26 | |||
| 27 | for (const record of value) { |
||
| 28 | record['id'] = record[id]; |
||
| 29 | Object.getPrototypeOf(globalThis.Store.classInstances[record[type]]).constructor.insert(record); |
||
| 30 | } |
||
| 31 | } |
||
| 32 | } |