Completed
Push — master ( 830089...3433cb )
by Mark
22s queued 10s
created

MorphOne.originalValue   A

Complexity

Conditions 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 12
rs 9.95
c 0
b 0
f 0
cc 1
1
import Relation from "../Relation";
2
3
/**
4
 *
5
 */
6
export default class MorphOne extends Relation {
7
8
    /**
9
     *
10
     * @param model
11
     */
12
    constructor(model) {
13
        super(model);
14
    }
15
16
    /**
17
     *
18
     * @return {*}
19
     */
20
    get value() {
21
        const type = this.$parent.constructor.className();
22
        const id = this.$parent.primaryKey;
23
        const idKeyName = `${this.$name}_id`;
24
        const idTypeName = `${this.$name}_type`;
25
26
        const lookUpKey = {};
27
        lookUpKey[idKeyName] = id;
28
        lookUpKey[idTypeName] = type;
29
30
        return this.model.find(lookUpKey);
31
    }
32
33
    /**
34
     *
35
     * @return {*}
36
     */
37
    get originalValue() {
38
        const type = this.$parent.constructor.className();
39
        const id = this.$parent.originalPrimaryKey;
40
        const idKeyName = `${this.$name}_id`;
41
        const idTypeName = `${this.$name}_type`;
42
43
        const lookUpKey = {};
44
        lookUpKey[idKeyName] = id;
45
        lookUpKey[idTypeName] = type;
46
47
        return this.model.find(lookUpKey);
48
    }
49
50
51
    /**
52
     *
53
     * @return {*[]}
54
     */
55
    getRelationalFields() {
56
        return [];
57
    }
58
}