• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

typeorm / typeorm / 15219332477

23 May 2025 09:13PM UTC coverage: 17.216% (-59.1%) from 76.346%
15219332477

Pull #11332

github

naorpeled
cr comments - move if block
Pull Request #11332: feat: add new undefined and null behavior flags

1603 of 12759 branches covered (12.56%)

Branch coverage included in aggregate %.

0 of 31 new or added lines in 3 files covered. (0.0%)

14132 existing lines in 166 files now uncovered.

4731 of 24033 relevant lines covered (19.69%)

60.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

7.14
/src/metadata/RelationIdMetadata.ts
1
import { RelationIdMetadataArgs } from "../metadata-args/RelationIdMetadataArgs"
2
import { EntityMetadata } from "./EntityMetadata"
3
import { RelationMetadata } from "./RelationMetadata"
4
import { SelectQueryBuilder } from "../query-builder/SelectQueryBuilder"
5
import { ObjectLiteral } from "../common/ObjectLiteral"
6
import { TypeORMError } from "../error"
1✔
7

8
/**
9
 * Contains all information about entity's relation count.
10
 */
11
export class RelationIdMetadata {
1✔
12
    // ---------------------------------------------------------------------
13
    // Public Properties
14
    // ---------------------------------------------------------------------
15

16
    /**
17
     * Entity metadata where this column metadata is.
18
     */
19
    entityMetadata: EntityMetadata
20

21
    /**
22
     * Relation from which ids will be extracted.
23
     */
24
    relation: RelationMetadata
25

26
    /**
27
     * Relation name which need to count.
28
     */
29
    relationNameOrFactory: string | ((object: any) => any)
30

31
    /**
32
     * Target class to which metadata is applied.
33
     */
34
    target: Function | string
35

36
    /**
37
     * Target's property name to which this metadata is applied.
38
     */
39
    propertyName: string
40

41
    /**
42
     * Alias of the joined (destination) table.
43
     */
44
    alias?: string
45

46
    /**
47
     * Extra condition applied to "ON" section of join.
48
     */
49
    queryBuilderFactory?: (
50
        qb: SelectQueryBuilder<any>,
51
    ) => SelectQueryBuilder<any>
52

53
    // ---------------------------------------------------------------------
54
    // Constructor
55
    // ---------------------------------------------------------------------
56

57
    constructor(options: {
58
        entityMetadata: EntityMetadata
59
        args: RelationIdMetadataArgs
60
    }) {
UNCOV
61
        this.entityMetadata = options.entityMetadata
×
UNCOV
62
        this.target = options.args.target
×
UNCOV
63
        this.propertyName = options.args.propertyName
×
UNCOV
64
        this.relationNameOrFactory = options.args.relation
×
UNCOV
65
        this.alias = options.args.alias
×
UNCOV
66
        this.queryBuilderFactory = options.args.queryBuilderFactory
×
67
    }
68

69
    // ---------------------------------------------------------------------
70
    // Public Methods
71
    // ---------------------------------------------------------------------
72

73
    /**
74
     * Sets relation id value from the given entity.
75
     *
76
     * todo: make it to work in embeds as well.
77
     */
78
    setValue(entity: ObjectLiteral) {
UNCOV
79
        const inverseEntity = this.relation.getEntityValue(entity)
×
80

UNCOV
81
        if (Array.isArray(inverseEntity)) {
×
UNCOV
82
            entity[this.propertyName] = inverseEntity
×
83
                .map((item) => {
UNCOV
84
                    return this.relation.inverseEntityMetadata.getEntityIdMixedMap(
×
85
                        item,
86
                    )
87
                })
UNCOV
88
                .filter((item) => item !== null && item !== undefined)
×
89
        } else {
90
            const value =
UNCOV
91
                this.relation.inverseEntityMetadata.getEntityIdMixedMap(
×
92
                    inverseEntity,
93
                )
UNCOV
94
            if (value !== undefined) entity[this.propertyName] = value
×
95
        }
96
    }
97

98
    // ---------------------------------------------------------------------
99
    // Public Builder Methods
100
    // ---------------------------------------------------------------------
101

102
    /**
103
     * Builds some depend relation id properties.
104
     * This builder method should be used only after entity metadata, its properties map and all relations are build.
105
     */
106
    build() {
107
        const propertyPath =
UNCOV
108
            typeof this.relationNameOrFactory === "function"
×
109
                ? this.relationNameOrFactory(this.entityMetadata.propertiesMap)
110
                : this.relationNameOrFactory
111
        const relation =
UNCOV
112
            this.entityMetadata.findRelationWithPropertyPath(propertyPath)
×
UNCOV
113
        if (!relation)
×
114
            throw new TypeORMError(
×
115
                `Cannot find relation ${propertyPath}. Wrong relation specified for @RelationId decorator.`,
116
            )
117

UNCOV
118
        this.relation = relation
×
119
    }
120
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc