• 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.76
/src/query-builder/relation-count/RelationCountMetadataToAttributeTransformer.ts
1
import { QueryExpressionMap } from "../QueryExpressionMap"
2
import { RelationCountMetadata } from "../../metadata/RelationCountMetadata"
3
import { RelationCountAttribute } from "./RelationCountAttribute"
1✔
4

5
export class RelationCountMetadataToAttributeTransformer {
1✔
6
    // -------------------------------------------------------------------------
7
    // Constructor
8
    // -------------------------------------------------------------------------
9

UNCOV
10
    constructor(protected expressionMap: QueryExpressionMap) {}
×
11

12
    // -------------------------------------------------------------------------
13
    // Public Methods
14
    // -------------------------------------------------------------------------
15

16
    transform() {
17
        // by example:
18
        // post has relation count:
19
        // @RelationCount(post => post.categories) categoryCount
20
        // category has relation count
21
        // @RelationCount(category => category.images) imageCount
22
        // we load post and join category
23
        // we expect post.categoryCount and post.category.imageCount to have relation counts
24

25
        // first create relation count attributes for all relation count metadatas of the main selected object (post from example)
UNCOV
26
        if (this.expressionMap.mainAlias) {
×
UNCOV
27
            this.expressionMap.mainAlias.metadata.relationCounts.forEach(
×
28
                (relationCount) => {
UNCOV
29
                    const attribute = this.metadataToAttribute(
×
30
                        this.expressionMap.mainAlias!.name,
31
                        relationCount,
32
                    )
UNCOV
33
                    this.expressionMap.relationCountAttributes.push(attribute)
×
34
                },
35
            )
36
        }
37

38
        // second create relation count attributes for all relation count metadatas of all joined objects (category from example)
UNCOV
39
        this.expressionMap.joinAttributes.forEach((join) => {
×
40
            // ensure this join has a metadata, because relation count can only work for real orm entities
UNCOV
41
            if (!join.metadata || join.metadata.isJunction) return
×
42

UNCOV
43
            join.metadata.relationCounts.forEach((relationCount) => {
×
UNCOV
44
                const attribute = this.metadataToAttribute(
×
45
                    join.alias.name,
46
                    relationCount,
47
                )
UNCOV
48
                this.expressionMap.relationCountAttributes.push(attribute)
×
49
            })
50
        })
51
    }
52

53
    // -------------------------------------------------------------------------
54
    // Private Methods
55
    // -------------------------------------------------------------------------
56

57
    private metadataToAttribute(
58
        parentAliasName: string,
59
        relationCount: RelationCountMetadata,
60
    ): RelationCountAttribute {
UNCOV
61
        return new RelationCountAttribute(this.expressionMap, {
×
62
            relationName:
63
                parentAliasName + "." + relationCount.relation.propertyName, // category.images
64
            mapToProperty: parentAliasName + "." + relationCount.propertyName, // category.imageIds
65
            alias: relationCount.alias,
66
            queryBuilderFactory: relationCount.queryBuilderFactory,
67
        })
68
    }
69
}
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