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 STI types on children in joins #3160

Merged
merged 2 commits into from May 29, 2021
Merged

Conversation

amaranth
Copy link
Contributor

@amaranth amaranth commented Nov 26, 2018

Note: This requires (and includes the commit from) PR #2967 otherwise you don't get the right type in the child's relation anyway.

If an STI child overrides a parent property and uses a different type doing a query on the parent type will skip the relation. This happens because the query's join is built using the parent relation but when mapping to an entity the child's relation is fetched so they don't match. Instead, we now use the relation's propertyPath to allow using relations that reference the same property. We also copy the child's relation type into the join to ensure we get the right type in the child as well.

This allows using a single table for multiple entities without using a
type column. Some setups infer the type from the context of how/where
the row is loaded.
If an STI child overrides a parent property and uses a different type
doing a query on the parent type will skip the relation. This happens
because the query's join is built using the parent relation but when
mapping to an entity the child's relation is fetched so they don't
match. Instead we now use the relation's propertyPath to allow using
relations that reference the same property. We also copy the child's
relation type into the join to ensure we get the right type in the child
as well.
@AlexMesser AlexMesser merged commit 60a6c5d into typeorm:master May 29, 2021
@AlexMesser
Copy link
Collaborator

thank you for contribution!

@pleerock
Copy link
Member

I'm going to revert this PR due to #8018 .

pleerock added a commit that referenced this pull request Oct 27, 2021
pleerock added a commit that referenced this pull request Oct 27, 2021
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

3 participants