Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BaseEntity finder methods to allow lazy relation conditions #5710

Merged
merged 2 commits into from Nov 11, 2021
Merged

Fix BaseEntity finder methods to allow lazy relation conditions #5710

merged 2 commits into from Nov 11, 2021

Conversation

bogdan
Copy link
Contributor

@bogdan bogdan commented Mar 18, 2020

The following code:

const category = await Category.findOne();
const post = Post.findOne({category})

Results in typecheck error when Post#category is a lazy relation while the finder does work.

@bogdan
Copy link
Contributor Author

bogdan commented May 15, 2020

@pleerock any feedback here?

@pleerock
Copy link
Member

TBH I would like to avoid merging this change, because I want to change lazy relation concept in the future versions.

@bogdan
Copy link
Contributor Author

bogdan commented May 17, 2020

@pleerock is there any described plan on that? Will there be breaking changes? What is expected date when this issue can be fixed with "lazy relation concent in the future versions"?

It is causing problems on our end because developers are very confused with this bug.

@pleerock
Copy link
Member

There is no roadmap, but I was previously mentioned about it in other issues. Okay, let's merge it if its problematic with current version.

@imnotjames imnotjames self-requested a review October 19, 2020 14:10
@bogdan
Copy link
Contributor Author

bogdan commented Dec 16, 2020

@imnotjames fixed the issue. Can you please review again?

@bogdan
Copy link
Contributor Author

bogdan commented Feb 1, 2021

@pleerock @imnotjames can you please merge this one?

@pleerock pleerock merged commit 0665ff5 into typeorm:master Nov 11, 2021
@alumni
Copy link
Contributor

alumni commented Nov 16, 2021

@bogdan This PR broke find/findOne when used from EntityManager.

const p = entityManager.findOne(Post, { where: { id: 1 }});

Under TS 4.4.4, the inferred type of p is { id: number } instead of Post

@bogdan
Copy link
Contributor Author

bogdan commented Nov 17, 2021

@alumni I can not reproduce that on current master. For me the type of p is Post | undefined.

@alumni
Copy link
Contributor

alumni commented Nov 19, 2021

@bogdan I check a bit more and it seems it's not particularly because of this PR, it only happens more often now, probably because of the added T | ... in line 11. We were already explicitly specifying the generic type in many cases (post = entityManager.find<Post>(Post, ...)) to avoid this problem. Probably if I find a simpler example than what I have now, I would also have a solution to it.

HeartPattern pushed a commit to HeartPattern/typeorm that referenced this pull request Nov 29, 2021
…onditions (typeorm#5710)

Co-authored-by: Umed Khudoiberdiev <pleerock.me@gmail.com>
@brandon-leapyear
Copy link

brandon-leapyear commented Feb 1, 2022

This is an old work account. Please reference @brandonchinn178 for all future communication


Note: the T | ... addition causes a regression: #8600

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants