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 find record in table if it has relation to another table #10834

Open
1 of 18 tasks
AngeliqueDenecheau opened this issue Apr 17, 2024 · 1 comment
Open
1 of 18 tasks

Comments

@AngeliqueDenecheau
Copy link

AngeliqueDenecheau commented Apr 17, 2024

Issue description

When trying to get a record from table, it returns null if it has a relation to another table.

Expected Behavior

Expected behavior is to return record with corresponding id.

Actual Behavior

I have a table "ingredient" with a column "deletedAt" and a column "authorId" which refers to "user" table.

I am using findOne method to get a record from this table with its id :

const ingredient = await this.getRepository(Ingredient).find({
  where: { id },
  withDeleted: true,
});

When the record has both a date of deletion and a relation to user, it returns null.
But when I remove one of the two, it returns the correct record.

Steps to reproduce

Here is the definition of ingredient entity :

@ManyToOne(() => User, { nullable: true, eager: true, onDelete: 'SET NULL' })
@Field(() => User, { nullable: true })
@IsOptional()
@IsObject()
@Type(() => User)
author?: User;

@DeleteDateColumn({ nullable: true, type: 'timestamptz' })
@Field(() => Date, { nullable: true })
@IsOptional()
@IsDate()
deletedAt?: Date;

My Environment

Dependency Version
Operating System Windows 11
Node.js version v20.11.1
Typescript version 5.4.5
TypeORM version 0.3.20
NestJS version 10.0.0
nestjs/typeorm version 10.0.2
PostgreSQL version 8.11.3

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?

No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

@DCampagnola
Copy link

I can't reproduce the bug.
Can you check if this is the expected behaviour?

        const user = await dataSource.getRepository(User).save({id: 1});
        await dataSource.getRepository(Ingredient).save({
            id: 1,
            author: user,
            deletedAt: new Date()
        });
        const foundIngredient = await dataSource.getRepository(Ingredient).findOne({withDeleted: true, where: {id: 1}});
        expect(foundIngredient?.author).to.be.eql(user);

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

2 participants