question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

loadRelationIds produces incorrect type?

See original GitHub issue

Issue type:

[ ] question [x] bug report [ ] feature request [ ] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [ ] mysql / mariadb [ ] oracle [x] postgres [ ] cockroachdb [ ] sqlite [ ] sqljs [ ] react-native [ ] expo

TypeORM version:

[ ] latest [ ] @next [x] 0.2.18 (or put your version here)

Steps to reproduce:

If I am using the loadRelationIds feature like this:

const orders = await manager.find(Order, {
    where: {
        // conditions
    },
    loadEagerRelations: false,
    loadRelationIds: {
        relations: [
            'customer',
        ],
    },
});

then the type of Order.customer in the orders array is still the entire Customer entity/object, while in fact it is just a string, the customer ID.

Is this expected or is this a bug? It seems that the return type of manager.find should be modified when loadRelationIds is set, and Order.customer should become a string instead of an object.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
jgladencommented, Apr 3, 2021

I’m not sure… but I got here looking for a solution and didn’t find one… without a lot of digging (maybe this is a documentation issue).

But disableMixedMap worked for me … applied to the above example might look something like this:

const orders = await manager.find(Order, {
    where: {
        // conditions
    },
    loadEagerRelations: false,
    loadRelationIds: {
        relations: [
            'customer',
        ],
        disableMixedMap: true
    },
});
2reactions
zevektorcommented, Jan 15, 2021

As of now, one should do something like:

entity.relation as unknown as ID_TYPE[]

But I don’t think it’s ideal

Read more comments on GitHub >

github_iconTop Results From Across the Web

Relations | TypeORM Docs
When we set @JoinColumn , it automatically creates a column in the database named propertyName + referencedColumnName . For example: @ManyToOne(type => Category ......
Read more >
Using TypeScript with the MySQL Database - InfoQ
Problem. JavaScript lacks several features that are used by large-scale ... Creates a primary column of type int that is automatically ...
Read more >
Class Connection - typeorm
Connection is a single database ORM connection to a specific database. Its not required to be a database connection, depend on database type...
Read more >
TypeORM: Load relations with only certain specified fields
That being said, if you have the correct OneToMany relation setup in your entity @OneToMany(type => Post, post => post.user) posts: Post.
Read more >
Nest + gql + typeORM(@nestjs/typeorm) (7) typeORM ...
Ride entity @OneToOne((type) => Chat, (chat) => chat.ride, ... 생략 @Field(() => Boolean) @Column({ default: false }) verified: boolean;.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found