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

bigNumberStrings: false option isn't work properly with relationship. #11226

Open
1 of 18 tasks
changchanghwang opened this issue Jan 7, 2025 · 0 comments
Open
1 of 18 tasks

Comments

@changchanghwang
Copy link

changchanghwang commented Jan 7, 2025

Issue description

The bigNumberStrings: false option triggers child entity's orphanedRowAction even when there are no changes

Expected Behavior

when save a with no change in bs, just update a. not any mutation query for b

 UPDATE `a` SET `name` = ? WHERE `id` IN (?) -- PARAMETERS: ["test2",2]

Actual Behavior

typeORM delete bs by orphanedRowAction

image

Steps to reproduce

import "reflect-metadata";
import {
  Column,
  DataSource,
  Entity,
  ManyToOne,
  OneToMany,
  PrimaryGeneratedColumn,
} from "typeorm";
import * as express from "express";

@Entity()
class A {
  @PrimaryGeneratedColumn()
  id!: number;

  @Column({ type: "varchar", length: 255 })
  name!: string;

  @OneToMany(() => B, (b) => b.a, { cascade: true, eager: true })
  bs!: B[];

  constructor(args?: { name: string }) {
    if (args) {
      this.name = args.name;
      this.bs = Array.from({ length: 5 }, (_, i) => new B({ value: i }));
    }
  }
}

@Entity()
class B {
  @PrimaryGeneratedColumn({ unsigned: true, type: "bigint" })
  id!: number;

  @Column({ type: "int" })
  value!: number;

  @ManyToOne(() => A, (a) => a.bs, { orphanedRowAction: "delete" })
  a!: never;

  constructor(args?: { value: number }) {
    if (args) {
      this.value = args.value;
    }
  }
}

async function initDB() {
  const connection = new DataSource({
    type: "mysql",
    host: "localhost",
    port: 3306,
    username: "root",
    password: "1234",
    database: "test",
    bigNumberStrings: false,
    synchronize: true,
    logging: true,
    entities: [A, B],
  });

  await connection.initialize();

  return connection;
}

(async () => {
  const app = express();

  const db = await initDB();

  app.get("/save", async (_, res) => {
    const a = new A({ name: "test" });

    await db.manager.save(a);

    res.send("pong");
  });

  app.get("/update", async (_, res) => {
    const [a] = await db.manager.find(A, {
      where: {
        name: "test",
      },
    });

    a.name = "test2";

    await db.manager.save([a]);

    res.send(a);
  });

  app.listen(3333, () => {
    console.log("Server is running on port 3333");
  });
})();

My Environment

Dependency Version
Operating System
Node.js version 20.17.0
Typescript version 5.7.2
TypeORM version 0.3.20

Additional Context

No response

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

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

Yes, I have the time, but I don't know how to start. I would need guidance.

@changchanghwang changchanghwang changed the title bigNumberStrings: false trigger orphanedRowAction with using cascade bigNumberStrings false option isn't work properly with relationship. Jan 7, 2025
@changchanghwang changchanghwang changed the title bigNumberStrings false option isn't work properly with relationship. bigNumberStrings: false option isn't work properly with relationship. Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant