Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent modification of the FindOptions.relations (#7887)
because of how we modify it as part of a recursive function we were erasing the `relations` array when iterating over them. this fixes that so we don't mess with the inputs like that and instead copy it
- Loading branch information
1 parent
1de2e13
commit a2fcad6
Showing
4 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Entity, JoinColumn, OneToOne, PrimaryGeneratedColumn } from "../../../../src"; | ||
import { ExampleText } from "./ExampleText"; | ||
|
||
@Entity() | ||
export class Example { | ||
@PrimaryGeneratedColumn() | ||
id: string; | ||
|
||
@OneToOne(() => ExampleText) | ||
@JoinColumn() | ||
exampleText: ExampleText; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Entity, PrimaryGeneratedColumn } from "../../../../src"; | ||
|
||
@Entity() | ||
export class ExampleText { | ||
@PrimaryGeneratedColumn() | ||
id: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import "reflect-metadata"; | ||
import { expect } from "chai"; | ||
import { Connection } from "../../../src"; | ||
import { closeTestingConnections, createTestingConnections, reloadTestingDatabases } from "../../utils/test-utils"; | ||
import { Example } from "./entity/Example"; | ||
import { ExampleText } from "./entity/ExampleText"; | ||
|
||
describe.only("github issues > #7882 .findOne reduces relations to an empty array", () => { | ||
|
||
let connections: Connection[]; | ||
before(async () => { | ||
connections = await createTestingConnections({ | ||
enabledDrivers: [ "sqlite" ], | ||
entities: [ Example, ExampleText ], | ||
schemaCreate: false, | ||
dropSchema: true | ||
}); | ||
}); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should delete all documents related to search pattern", () => Promise.all(connections.map(async connection => { | ||
const relations = [ "exampleText" ]; | ||
|
||
const repo = connection.getRepository(Example); | ||
|
||
await repo.find({ relations }); | ||
|
||
expect(relations).to.be.eql([ "exampleText" ]); | ||
}))); | ||
}); |