• 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

12.5
/src/query-builder/relation-id/RelationIdAttribute.ts
1
import { RelationMetadata } from "../../metadata/RelationMetadata"
2
import { QueryBuilderUtils } from "../QueryBuilderUtils"
1✔
3
import { EntityMetadata } from "../../metadata/EntityMetadata"
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
/**
10
 * Stores all join relation id attributes which will be used to build a JOIN query.
11
 */
12
export class RelationIdAttribute {
1✔
13
    // -------------------------------------------------------------------------
14
    // Public Properties
15
    // -------------------------------------------------------------------------
16

17
    /**
18
     * Alias of the joined (destination) table.
19
     */
20
    alias?: string
21

22
    /**
23
     * Name of relation.
24
     */
25
    relationName: string
26

27
    /**
28
     * Property + alias of the object where to joined data should be mapped.
29
     */
30
    mapToProperty: string
31

32
    /**
33
     * Extra condition applied to "ON" section of join.
34
     */
35
    queryBuilderFactory?: (
36
        qb: SelectQueryBuilder<any>,
37
    ) => SelectQueryBuilder<any>
38

39
    /**
40
     * Indicates if relation id should NOT be loaded as id map.
41
     */
UNCOV
42
    disableMixedMap = false
×
43

44
    // -------------------------------------------------------------------------
45
    // Constructor
46
    // -------------------------------------------------------------------------
47

48
    constructor(
UNCOV
49
        private queryExpressionMap: QueryExpressionMap,
×
50
        relationIdAttribute?: Partial<RelationIdAttribute>,
51
    ) {
UNCOV
52
        ObjectUtils.assign(this, relationIdAttribute || {})
×
53
    }
54

55
    // -------------------------------------------------------------------------
56
    // Public Methods
57
    // -------------------------------------------------------------------------
58

59
    get joinInverseSideMetadata(): EntityMetadata {
UNCOV
60
        return this.relation.inverseEntityMetadata
×
61
    }
62

63
    /**
64
     * Alias of the parent of this join.
65
     * For example, if we join ("post.category", "categoryAlias") then "post" is a parent alias.
66
     * This value is extracted from entityOrProperty value.
67
     * This is available when join was made using "post.category" syntax.
68
     */
69
    get parentAlias(): string {
UNCOV
70
        if (!QueryBuilderUtils.isAliasProperty(this.relationName))
×
71
            throw new TypeORMError(
×
72
                `Given value must be a string representation of alias property`,
73
            )
74

UNCOV
75
        return this.relationName.substr(0, this.relationName.indexOf("."))
×
76
    }
77

78
    /**
79
     * Relation property name of the parent.
80
     * This is used to understand what is joined.
81
     * For example, if we join ("post.category", "categoryAlias") then "category" is a relation property.
82
     * This value is extracted from entityOrProperty value.
83
     * This is available when join was made using "post.category" syntax.
84
     */
85
    get relationPropertyPath(): string {
UNCOV
86
        if (!QueryBuilderUtils.isAliasProperty(this.relationName))
×
87
            throw new TypeORMError(
×
88
                `Given value must be a string representation of alias property`,
89
            )
90

UNCOV
91
        return this.relationName.substr(this.relationName.indexOf(".") + 1)
×
92
    }
93

94
    /**
95
     * Relation of the parent.
96
     * This is used to understand what is joined.
97
     * This is available when join was made using "post.category" syntax.
98
     */
99
    get relation(): RelationMetadata {
UNCOV
100
        if (!QueryBuilderUtils.isAliasProperty(this.relationName))
×
101
            throw new TypeORMError(
×
102
                `Given value must be a string representation of alias property`,
103
            )
104

UNCOV
105
        const relationOwnerSelection = this.queryExpressionMap.findAliasByName(
×
106
            this.parentAlias!,
107
        )
108
        const relation =
UNCOV
109
            relationOwnerSelection.metadata.findRelationWithPropertyPath(
×
110
                this.relationPropertyPath!,
111
            )
UNCOV
112
        if (!relation)
×
113
            throw new TypeORMError(
×
114
                `Relation with property path ${this.relationPropertyPath} in entity was not found.`,
115
            )
UNCOV
116
        return relation
×
117
    }
118

119
    /**
120
     * Generates alias of junction table, whose ids we get.
121
     */
122
    get junctionAlias(): string {
UNCOV
123
        const [parentAlias, relationProperty] = this.relationName.split(".")
×
UNCOV
124
        return parentAlias + "_" + relationProperty + "_rid"
×
125
    }
126

127
    /**
128
     * Metadata of the joined entity.
129
     * If extra condition without entity was joined, then it will return undefined.
130
     */
131
    get junctionMetadata(): EntityMetadata {
132
        return this.relation.junctionEntityMetadata!
×
133
    }
134

135
    get mapToPropertyParentAlias(): string {
136
        return this.mapToProperty.substr(0, this.mapToProperty.indexOf("."))
×
137
    }
138

139
    get mapToPropertyPropertyPath(): string {
UNCOV
140
        return this.mapToProperty.substr(this.mapToProperty.indexOf(".") + 1)
×
141
    }
142
}
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