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

Fail on Update when reference exists together with FK: multiple assignments to same column #8723

Closed
UyumazHakan opened this issue Mar 3, 2022 · 0 comments · Fixed by #8724

Comments

@UyumazHakan
Copy link
Contributor

UyumazHakan commented Mar 3, 2022

Issue Description

When a reference to a foreign entity exists together with a foreign key in the entity, TypeORM fails to update the entity with multiple assignments to same column error. This is also discussed in issue #2651. Please see the example in Actual Behavior

Expected Behavior

It is able to update getting the entity in the DB by passing only one id.

Actual Behavior

It is adding update expression for both the id in the reference and FK in the entity itself. This leads multiple assignments to same column error for Postgresql.

QueryFailedError: multiple assignments to same column "user_id"
      at QueryFailedError.TypeORMError [as constructor] (src/error/TypeORMError.ts:7:9)
      at new QueryFailedError (src/error/QueryFailedError.ts:9:9)
      at PostgresQueryRunner.<anonymous> (src/driver/postgres/PostgresQueryRunner.ts:263:19)
      at step (node_modules/tslib/tslib.js:143:27)
      at Object.throw (node_modules/tslib/tslib.js:124:57)
      at rejected (node_modules/tslib/tslib.js:115:69)
      at processTicksAndRejections (internal/process/task_queues.js:95:5)

Steps to Reproduce

        const photoRepository = connection.getRepository(Photo);
        const userRepository = connection.getRepository(User);

        const user = await userRepository.save({ id: 1, name: "Test" });
        const photo = await photoRepository.save({ id: 1 });

        await photoRepository.update({ id: photo.id }, { user, userId: user.id });

My Environment

Dependency Version
Operating System macOS Monterey
Node.js version v14.18.0
Typescript version 4.5.5
TypeORM version 0.2.41

Additional Context

Relevant Database Driver(s)

DB Type Reproducible
aurora-data-api no
aurora-data-api-pg no
better-sqlite3 no
cockroachdb no
cordova no
expo no
mongodb no
mysql no
nativescript no
oracle no
postgres yes
react-native no
sap 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.
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.

1 participant