• 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

11.11
/src/query-builder/relation-count/RelationCountAttribute.ts
1
import { EntityMetadata } from "../../metadata/EntityMetadata"
2
import { QueryBuilderUtils } from "../QueryBuilderUtils"
1✔
3
import { RelationMetadata } from "../../metadata/RelationMetadata"
4
import { QueryExpressionMap } from "../QueryExpressionMap"
5
import { SelectQueryBuilder } from "../SelectQueryBuilder"
6
import { ObjectUtils } from "../../util/ObjectUtils"
1✔
7
import { TypeORMError } from "../../error/TypeORMError"
1✔
8

9
export class RelationCountAttribute {
1✔
10
    /**
11
     * Alias of the joined (destination) table.
12
     */
13
    alias?: string
14

15
    /**
16
     * Name of relation.
17
     */
18
    relationName: string
19

20
    /**
21
     * Property + alias of the object where to joined data should be mapped.
22
     */
23
    mapToProperty: string
24

25
    /**
26
     * Extra condition applied to "ON" section of join.
27
     */
28
    queryBuilderFactory?: (
29
        qb: SelectQueryBuilder<any>,
30
    ) => SelectQueryBuilder<any>
31

32
    // -------------------------------------------------------------------------
33
    // Constructor
34
    // -------------------------------------------------------------------------
35

36
    constructor(
UNCOV
37
        private expressionMap: QueryExpressionMap,
×
38
        relationCountAttribute?: Partial<RelationCountAttribute>,
39
    ) {
UNCOV
40
        ObjectUtils.assign(this, relationCountAttribute || {})
×
41
    }
42

43
    // -------------------------------------------------------------------------
44
    // Public Methods
45
    // -------------------------------------------------------------------------
46

47
    get joinInverseSideMetadata(): EntityMetadata {
UNCOV
48
        return this.relation.inverseEntityMetadata
×
49
    }
50

51
    /**
52
     * Alias of the parent of this join.
53
     * For example, if we join ("post.category", "categoryAlias") then "post" is a parent alias.
54
     * This value is extracted from entityOrProperty value.
55
     * This is available when join was made using "post.category" syntax.
56
     */
57
    get parentAlias(): string {
UNCOV
58
        if (!QueryBuilderUtils.isAliasProperty(this.relationName))
×
59
            throw new TypeORMError(
×
60
                `Given value must be a string representation of alias property`,
61
            )
62

UNCOV
63
        return this.relationName.split(".")[0]
×
64
    }
65

66
    /**
67
     * Relation property name of the parent.
68
     * This is used to understand what is joined.
69
     * For example, if we join ("post.category", "categoryAlias") then "category" is a relation property.
70
     * This value is extracted from entityOrProperty value.
71
     * This is available when join was made using "post.category" syntax.
72
     */
73
    get relationProperty(): string | undefined {
74
        if (!QueryBuilderUtils.isAliasProperty(this.relationName))
×
75
            throw new TypeORMError(
×
76
                `Given value is a string representation of alias property`,
77
            )
78

79
        return this.relationName.split(".")[1]
×
80
    }
81

82
    get junctionAlias(): string {
UNCOV
83
        const [parentAlias, relationProperty] = this.relationName.split(".")
×
UNCOV
84
        return parentAlias + "_" + relationProperty + "_rc"
×
85
    }
86

87
    /**
88
     * Relation of the parent.
89
     * This is used to understand what is joined.
90
     * This is available when join was made using "post.category" syntax.
91
     */
92
    get relation(): RelationMetadata {
UNCOV
93
        if (!QueryBuilderUtils.isAliasProperty(this.relationName))
×
94
            throw new TypeORMError(
×
95
                `Given value is a string representation of alias property`,
96
            )
97

UNCOV
98
        const [parentAlias, propertyPath] = this.relationName.split(".")
×
99
        const relationOwnerSelection =
UNCOV
100
            this.expressionMap.findAliasByName(parentAlias)
×
101
        const relation =
UNCOV
102
            relationOwnerSelection.metadata.findRelationWithPropertyPath(
×
103
                propertyPath,
104
            )
UNCOV
105
        if (!relation)
×
106
            throw new TypeORMError(
×
107
                `Relation with property path ${propertyPath} in entity was not found.`,
108
            )
UNCOV
109
        return relation
×
110
    }
111

112
    /**
113
     * Metadata of the joined entity.
114
     * If table without entity was joined, then it will return undefined.
115
     */
116
    get metadata(): EntityMetadata {
117
        if (!QueryBuilderUtils.isAliasProperty(this.relationName))
×
118
            throw new TypeORMError(
×
119
                `Given value is a string representation of alias property`,
120
            )
121

122
        const parentAlias = this.relationName.split(".")[0]
×
123
        const selection = this.expressionMap.findAliasByName(parentAlias)
×
124
        return selection.metadata
×
125
    }
126

127
    get mapToPropertyPropertyName(): string {
UNCOV
128
        return this.mapToProperty!.split(".")[1]
×
129
    }
130
}
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