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

🤨 Cannot manually insert type in discriminator column of parent entity class when using single table inheritance when creating instance of parent entity #9033

Closed
AlfaHound opened this issue May 23, 2022 · 1 comment · Fixed by #9034

Comments

@AlfaHound
Copy link

AlfaHound commented May 23, 2022

Issue Description

Not sure if this is the intended behavior or not, but is it possible to directly just use the parent entity class when using STI and manually set the type? I have been trying to do bulk inserts with fake data by using the parent class, but the 'type' column gets overwritten with the parent entity class's name.

Steps to Reproduce

  1. Copy paste single table inheritance example from docs,
  2. Add column for type in the Content class
  3. Attempt to insert data into the Content table using querybuilder, or if you want to implement base entity, the create() method, with the type field set to any of the child entities.
  4. Inserts will work, but the results will have type column overwritten with "Content", regardless if it is input or not.

My Environment

Dependency Version
Operating System Windows 10
Node.js version 14.17.5
Typescript version 4.5.2
TypeORM version 0.3.6

Relevant Database Driver(s)

DB Type Reproducible
aurora-mysql no
aurora-postgres no
better-sqlite3 yes
cockroachdb no
cordova no
expo no
mongodb no
mysql no
nativescript no
oracle no
postgres no
react-native no
sap no
spanner no
sqlite no
sqlite-abstract no
sqljs no
sqlserver no

Are you willing to resolve this issue by submitting a Pull Request?

  • ✖️ Yes, I have the time, and I know how to start.
  • ✖️ Yes, I have the time, but I don't know how to start. I would need guidance.
  • ✖️ No, I don’t have the time, but I can support (using donations) development.
  • ✅ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.
@AlfaHound AlfaHound changed the title Cannot insert correct type in discriminator column of parent entity class when single table inheritance Cannot insert correct type in discriminator column of parent entity class when using single table inheritance May 23, 2022
@AlfaHound AlfaHound changed the title Cannot insert correct type in discriminator column of parent entity class when using single table inheritance Cannot manually insert type in discriminator column of parent entity class when using single table inheritance May 23, 2022
@AlfaHound AlfaHound changed the title Cannot manually insert type in discriminator column of parent entity class when using single table inheritance 🤨 Cannot manually insert type in discriminator column of parent entity class when using single table inheritance May 23, 2022
@AlfaHound AlfaHound changed the title 🤨 Cannot manually insert type in discriminator column of parent entity class when using single table inheritance 🤨 Cannot manually insert type in discriminator column of parent entity class when using single table inheritance when creating instance of parent entity May 23, 2022
felix-gohla added a commit to giz-berlin/typeorm that referenced this issue May 27, 2022
This commit allows using an instance of a base class in a
Single Table Inheritance scenario and setting the discriminator value
manually.

Related to: typeorm#9033
felix-gohla added a commit to giz-berlin/typeorm that referenced this issue May 27, 2022
This commit allows using an instance of a base class in a
Single Table Inheritance scenario and setting the discriminator value
manually.

Related to: typeorm#9033
felix-gohla added a commit to giz-berlin/typeorm that referenced this issue May 27, 2022
felix-gohla added a commit to giz-berlin/typeorm that referenced this issue May 27, 2022
This commit allows using an instance of a base class in a
Single Table Inheritance scenario and setting the discriminator value
manually.

Related to: typeorm#9033
felix-gohla added a commit to giz-berlin/typeorm that referenced this issue May 27, 2022
felix-gohla added a commit to giz-berlin/typeorm that referenced this issue May 27, 2022
This commit allows using an instance of a base class in a
Single Table Inheritance scenario and setting the discriminator value
manually.

Related to: typeorm#9033
felix-gohla added a commit to giz-berlin/typeorm that referenced this issue May 27, 2022
felix-gohla added a commit to giz-berlin/typeorm that referenced this issue May 27, 2022
This commit allows using an instance of a base class in a
Single Table Inheritance scenario and setting the discriminator value
manually.

Related to: typeorm#9033
felix-gohla added a commit to giz-berlin/typeorm that referenced this issue Aug 22, 2022
felix-gohla added a commit to giz-berlin/typeorm that referenced this issue Aug 22, 2022
This commit allows using an instance of a base class in a
Single Table Inheritance scenario and setting the discriminator value
manually.

Related to: typeorm#9033
felix-gohla added a commit to giz-berlin/typeorm that referenced this issue Oct 2, 2022
felix-gohla added a commit to giz-berlin/typeorm that referenced this issue Oct 2, 2022
This commit allows using an instance of a base class in a
Single Table Inheritance scenario and setting the discriminator value
manually.

Related to: typeorm#9033
felix-gohla added a commit to giz-berlin/typeorm that referenced this issue Nov 7, 2022
felix-gohla added a commit to giz-berlin/typeorm that referenced this issue Nov 7, 2022
This commit allows using an instance of a base class in a
Single Table Inheritance scenario and setting the discriminator value
manually.

Related to: typeorm#9033
felix-gohla added a commit to giz-berlin/typeorm that referenced this issue Dec 3, 2022
felix-gohla added a commit to giz-berlin/typeorm that referenced this issue Dec 3, 2022
This commit allows using an instance of a base class in a
Single Table Inheritance scenario and setting the discriminator value
manually.

Related to: typeorm#9033
@rebelchris
Copy link

Experiencing the same issue on a Postgres database.
Even by passing type or not it will default to the type of the entity.

rebelchris added a commit to dailydotdev/daily-api that referenced this issue Jan 28, 2023
Apparently there is an issue with using the type column on insertion.
It will overwrite with the Type of the entity.

typeorm/typeorm#9033

This will retro-fix the types that got overwritten via import only.

WT-962 #done
felix-gohla added a commit to giz-berlin/typeorm that referenced this issue Feb 9, 2023
felix-gohla added a commit to giz-berlin/typeorm that referenced this issue Feb 9, 2023
This commit allows using an instance of a base class in a
Single Table Inheritance scenario and setting the discriminator value
manually.

Related to: typeorm#9033
felix-gohla added a commit to giz-berlin/typeorm that referenced this issue Apr 12, 2023
felix-gohla added a commit to giz-berlin/typeorm that referenced this issue Apr 12, 2023
This commit allows using an instance of a base class in a
Single Table Inheritance scenario and setting the discriminator value
manually.

Related to: typeorm#9033
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants