-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow to pass ObjectLiteral in mongo find where condition (#9632)
Closes: #9518
- Loading branch information
1 parent
b97633b
commit 4eda5df
Showing
3 changed files
with
61 additions
and
2 deletions.
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,10 @@ | ||
import { Column, Entity, ObjectID, ObjectIdColumn } from "../../../../src" | ||
|
||
@Entity() | ||
export class Post { | ||
@ObjectIdColumn() | ||
id: ObjectID | ||
|
||
@Column() | ||
title: 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,46 @@ | ||
import "reflect-metadata" | ||
import { | ||
createTestingConnections, | ||
closeTestingConnections, | ||
reloadTestingDatabases, | ||
} from "../../utils/test-utils" | ||
import { DataSource } from "../../../src/data-source/DataSource" | ||
import { expect } from "chai" | ||
import { Post } from "./entity/Post" | ||
|
||
describe("github issues > #9518 Can't pass ObjectLiteral in MongoRepository.find where condition due to typings", () => { | ||
let connections: DataSource[] | ||
before( | ||
async () => | ||
(connections = await createTestingConnections({ | ||
entities: [Post], | ||
enabledDrivers: ["mongodb"], | ||
})), | ||
) | ||
beforeEach(() => reloadTestingDatabases(connections)) | ||
after(() => closeTestingConnections(connections)) | ||
|
||
it("should be able to use ObjectLiteral in find where condition", () => | ||
Promise.all( | ||
connections.map(async (connection) => { | ||
const postRepository = connection.getMongoRepository(Post) | ||
|
||
const firstPost = new Post() | ||
firstPost.title = "Post #1" | ||
await postRepository.save(firstPost) | ||
|
||
const secondPost = new Post() | ||
secondPost.title = "Post #2" | ||
await postRepository.save(secondPost) | ||
|
||
const loadedPosts = await postRepository.find({ | ||
where: { | ||
title: { $in: ["Post #1"] }, | ||
}, | ||
}) | ||
|
||
expect(loadedPosts).to.have.length(1) | ||
expect(loadedPosts[0].title).to.eql("Post #1") | ||
}), | ||
)) | ||
}) |