From b0c37d67f44140a7d7e3dd8aa51d5cf28762c57b Mon Sep 17 00:00:00 2001 From: Umed Khudoiberdiev Date: Tue, 31 Oct 2017 10:51:33 +0500 Subject: [PATCH] refactoring persistence --- README-zh_CN.md | 6 +- README.md | 12 ++-- docs/connection-api.md | 6 +- docs/connection.md | 2 +- docs/eager-and-lazy-relations.md | 2 +- docs/entities.md | 10 ++-- docs/entity-manager-api.md | 9 +-- docs/example-with-express.md | 4 +- docs/relational-query-builder.md | 4 +- docs/repository-api.md | 9 +-- docs/working-with-entity-manager.md | 3 +- docs/working-with-repository.md | 2 +- sample/sample11-all-types-entity/app.ts | 2 +- sample/sample13-everywhere-abstraction/app.ts | 4 +- .../sample25-insert-from-inverse-side/app.ts | 8 +-- sample/sample26-embedded-tables/app.ts | 2 +- sample/sample27-composite-primary-keys/app.ts | 2 +- .../sample28-single-table-inheritance/app.ts | 18 +++--- .../sample29-class-table-inheritance/app.ts | 18 +++--- sample/sample5-subscribers/app.ts | 2 +- sample/sample6-abstract-table/app.ts | 4 +- sample/sample9-entity-listeners/app.ts | 2 +- src/commands/InitCommand.ts | 2 +- src/entity-manager/EntityManager.ts | 5 +- src/platform/PlatformTools.ts | 6 +- src/repository/BaseEntity.ts | 14 ++++- src/repository/MongoRepository.ts | 4 +- src/repository/Repository.ts | 43 +++++++------ .../columns-getters-setters.ts | 2 +- .../columns/no-select/columns-no-select.ts | 2 +- .../columns/readonly/columns-readonly.ts | 2 +- .../value-transformer/value-transformer.ts | 2 +- .../connection-manager/connection-manager.ts | 8 +-- test/functional/connection/connection.ts | 4 +- .../column-types/mssql/column-types-mssql.ts | 6 +- .../column-types/mysql/column-types-mysql.ts | 6 +- .../postgres/column-types-postgres.ts | 6 +- .../sqlite/column-types-sqlite.ts | 4 +- .../mssql-parameters/mssql-parameters.ts | 12 ++-- .../embedded/query-builder-embedded.ts | 2 +- .../convert-to-entity/convert-to-entity.ts | 6 +- .../basic-functionality.ts | 6 +- ...tiple-primary-columns-with-nested-embed.ts | 4 +- .../multiple-primary-columns.ts | 4 +- .../outer-primary-column.ts | 4 +- .../embedded/prefix/embedded-prefix.ts | 2 +- test/functional/entity-model/entity-model.ts | 2 +- test/functional/json/jsonb.ts | 6 +- .../mongodb-repository-actions.ts | 6 +- .../persistence-basic-functionality.ts | 12 ++-- .../persistence-custom-column-names.ts | 10 ++-- .../entity-updation/entity/PostComplex.ts | 18 ++++++ .../entity/PostDefaultValues.ts | 14 +++++ .../entity-updation/entity/PostEmbedded.ts | 20 +++++++ .../entity-updation/entity/PostIncrement.ts | 14 +++++ .../entity/PostMultiplePrimaryKeys.ts | 17 ++++++ .../entity/PostSpecialColumns.ts | 26 ++++++++ .../entity-updation/entity/PostUuid.ts | 14 +++++ .../persistence-entity-updation.ts | 28 +++++++++ .../many-to-many/persistence-many-to-many.ts | 14 ++--- .../persistence-many-to-one-bi-directional.ts | 26 ++++---- ...persistence-many-to-one-uni-directional.ts | 26 ++++---- .../null-and-default-behaviour.ts | 10 ++-- .../one-to-many/persistence-one-to-many.ts | 10 ++-- .../partial-persist/partial-persist.ts | 8 +-- ...ational-add-remove-many-to-many-inverse.ts | 60 +++++++++---------- ...lder-relational-add-remove-many-to-many.ts | 60 +++++++++---------- ...ilder-relational-add-remove-one-to-many.ts | 54 ++++++++--------- .../query-builder-relational-load-many.ts | 6 +- .../query-builder-relational-load-one.ts | 18 +++--- ...uery-builder-relational-set-many-to-one.ts | 48 +++++++-------- ...ilder-relational-set-one-to-one-inverse.ts | 48 +++++++-------- ...query-builder-relational-set-one-to-one.ts | 48 +++++++-------- .../basic-eager-relations.ts | 2 +- .../basic-lazy-relations.ts | 8 +-- .../named-columns-lazy-relations.ts | 6 +- ...named-tables-and-columns-lazy-relations.ts | 6 +- .../named-tables-lazy-relations.ts | 6 +- .../find-methods/repostiory-find-methods.ts | 12 ++-- .../repository-set-add-remove-relations.ts | 16 ++--- test/functional/uuid/mssql/uuid-mssql.ts | 8 +-- test/functional/uuid/mysql/uuid-mysql.ts | 2 +- .../functional/uuid/postgres/uuid-postgres.ts | 10 ++-- test/functional/uuid/sqlite/uuid-sqlite.ts | 8 +-- test/github-issues/1014/issue-1014.ts | 2 +- test/github-issues/1042/issue-1042.ts | 8 +-- test/github-issues/151/issue-151.ts | 2 +- test/github-issues/161/issue-161.ts | 6 +- test/github-issues/204/issue-204.ts | 2 +- test/github-issues/433/issue-433.ts | 2 +- test/github-issues/463/issue-463.ts | 2 +- test/github-issues/485/issue-485.ts | 2 +- test/github-issues/513/issue-513.ts | 4 +- test/github-issues/703/issue-703.ts | 4 +- test/github-issues/720/issue-720.ts | 10 ++-- test/github-issues/836/issue-836.ts | 2 +- test/github-issues/838/issue-838.ts | 2 +- test/github-issues/966/issue-966.ts | 2 +- test/integration/sample1-simple-entity.ts | 2 +- test/integration/sample2-one-to-one.ts | 8 +-- test/integration/sample3-many-to-one.ts | 12 ++-- test/integration/sample4-many-to-many.ts | 12 ++-- test/utils/test-utils.ts | 8 +++ 103 files changed, 625 insertions(+), 461 deletions(-) create mode 100644 test/functional/persistence/entity-updation/entity/PostComplex.ts create mode 100644 test/functional/persistence/entity-updation/entity/PostDefaultValues.ts create mode 100644 test/functional/persistence/entity-updation/entity/PostEmbedded.ts create mode 100644 test/functional/persistence/entity-updation/entity/PostIncrement.ts create mode 100644 test/functional/persistence/entity-updation/entity/PostMultiplePrimaryKeys.ts create mode 100644 test/functional/persistence/entity-updation/entity/PostSpecialColumns.ts create mode 100644 test/functional/persistence/entity-updation/entity/PostUuid.ts create mode 100644 test/functional/persistence/entity-updation/persistence-entity-updation.ts diff --git a/README-zh_CN.md b/README-zh_CN.md index 23279752bc..a06d1e9e9d 100644 --- a/README-zh_CN.md +++ b/README-zh_CN.md @@ -432,7 +432,7 @@ createConnection(/*...*/).then(async connection => { let allPhotos = await photoRepository.find(); console.log("All photos from the db: ", allPhotos); - let firstPhoto = await photoRepository.findOneById(1); + let firstPhoto = await photoRepository.findOne(1); console.log("First photo from the db: ", firstPhoto); let meAndBearsPhoto = await photoRepository.findOne({ name: "Me and Bears" }); @@ -462,7 +462,7 @@ import {Photo} from "./entity/Photo"; createConnection(/*...*/).then(async connection => { /*...*/ - let photoToUpdate = await photoRepository.findOneById(1); + let photoToUpdate = await photoRepository.findOne(1); photoToUpdate.name = "Me, my friends and polar bears"; await photoRepository.save(photoToUpdate); @@ -483,7 +483,7 @@ import {Photo} from "./entity/Photo"; createConnection(/*...*/).then(async connection => { /*...*/ - let photoToRemove = await photoRepository.findOneById(1); + let photoToRemove = await photoRepository.findOne(1); await photoRepository.remove(photoToRemove); }).catch(error => console.log(error)); diff --git a/README.md b/README.md index c7fd3083c4..979408316d 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ user.age = 25; await repository.save(user); const allUsers = await repository.find(); -const firstUser = await repository.findOneById(1); +const firstUser = await repository.findOne(1); const timber = await repository.findOne({ firstName: "Timber", lastName: "Saw" }); await repository.remove(timber); @@ -149,7 +149,7 @@ user.age = 25; await user.save(); const allUsers = await User.find(); -const firstUser = await User.findOneById(1); +const firstUser = await User.findOne(1); const timber = await User.findOne({ firstName: "Timber", lastName: "Saw" }); await timber.remove(); @@ -711,7 +711,7 @@ createConnection(/*...*/).then(async connection => { let allPhotos = await photoRepository.find(); console.log("All photos from the db: ", allPhotos); - let firstPhoto = await photoRepository.findOneById(1); + let firstPhoto = await photoRepository.findOne(1); console.log("First photo from the db: ", firstPhoto); let meAndBearsPhoto = await photoRepository.findOne({ name: "Me and Bears" }); @@ -741,7 +741,7 @@ import {Photo} from "./entity/Photo"; createConnection(/*...*/).then(async connection => { /*...*/ - let photoToUpdate = await photoRepository.findOneById(1); + let photoToUpdate = await photoRepository.findOne(1); photoToUpdate.name = "Me, my friends and polar bears"; await photoRepository.save(photoToUpdate); @@ -761,7 +761,7 @@ import {Photo} from "./entity/Photo"; createConnection(/*...*/).then(async connection => { /*...*/ - let photoToRemove = await photoRepository.findOneById(1); + let photoToRemove = await photoRepository.findOne(1); await photoRepository.remove(photoToRemove); }).catch(error => console.log(error)); @@ -1186,7 +1186,7 @@ await connection.manager.save(photo); // now lets load them: const loadedPhoto = await connection .getRepository(Photo) - .findOneById(1, { relations: ["albums"] }); + .findOne(1, { relations: ["albums"] }); ``` `loadedPhoto` will be equal to: diff --git a/docs/connection-api.md b/docs/connection-api.md index e902240c1e..6aa77df9f0 100644 --- a/docs/connection-api.md +++ b/docs/connection-api.md @@ -156,7 +156,7 @@ Learn more about [Entity Manager and Repository](working-with-entity-manager.md) ```typescript const manager: EntityManager = connection.manager; // you can call manager methods, for example find: -const user = await manager.findOneById(1); +const user = await manager.findOne(1); ``` * `mongoManager` - `MongoEntityManager` used to work with connection entities in mongodb connections. @@ -165,7 +165,7 @@ For more information about MongoEntityManager see [MongoDB](./mongodb.md) docume ```typescript const manager: MongoEntityManager = connection.mongoManager; // you can call manager or mongodb-manager specific methods, for example find: -const user = await manager.findOneById(1); +const user = await manager.findOne(1); ``` * `connect` - Performs connection to the database. @@ -233,7 +233,7 @@ Learn more about [Repositories](working-with-entity-manager.md). ```typescript const repository = connection.getRepository(User); // now you can call repository methods, for example find: -const users = await repository.findOneById(1); +const users = await repository.findOne(1); ``` * `getTreeRepository` - Gets `TreeRepository` of the given entity. diff --git a/docs/connection.md b/docs/connection.md index eeba3816c3..3644fbf400 100644 --- a/docs/connection.md +++ b/docs/connection.md @@ -184,7 +184,7 @@ export class UserController { @Get("/users/:id") getAll(@Param("id") userId: number) { - return getRepository(User).findOneById(User); + return getRepository(User).findOne(userId); } } diff --git a/docs/eager-and-lazy-relations.md b/docs/eager-and-lazy-relations.md index 634045c03d..75627295b2 100644 --- a/docs/eager-and-lazy-relations.md +++ b/docs/eager-and-lazy-relations.md @@ -132,7 +132,7 @@ await connection.manager.save(question); Example how to load objects inside lazy relations: ```typescript -const question = await connection.getRepository(Question).findOneById(1); +const question = await connection.getRepository(Question).findOne(1); const answers = await question.answers; // you'll have all question's answers inside "answers" variable now ``` diff --git a/docs/entities.md b/docs/entities.md index cb5fdcb7ae..7ca616c60d 100644 --- a/docs/entities.md +++ b/docs/entities.md @@ -173,16 +173,16 @@ When you save entities using `save` it always tries to find a entity in the data If id/ids are found then it will update this row in the database. If there is no row with the id/ids, a new row will be inserted. -To find a entity by id you can use `manager.findOneById` or `repository.findOneById`. Example: +To find a entity by id you can use `manager.findOne` or `repository.findOne`. Example: ```typescript // find one by id with single primary key -const person = await connection.manager.findOneById(Person, 1); -const person = await connection.getRepository(Person).findOneById(1); +const person = await connection.manager.findOne(Person, 1); +const person = await connection.getRepository(Person).findOne(1); // find one by id with composite primary keys -const user = await connection.manager.findOneById(User, { firstName: "Umed", lastName: "Khudoiberdiev" }); -const user = await connection.getRepository(User).findOneById({ firstName: "Umed", lastName: "Khudoiberdiev" }); +const user = await connection.manager.findOne(User, { firstName: "Timber", lastName: "Saw" }); +const user = await connection.getRepository(User).findOne({ firstName: "Timber", lastName: "Saw" }); ``` ### Special columns diff --git a/docs/entity-manager-api.md b/docs/entity-manager-api.md index b0c3d7eca0..7cae6be3b6 100644 --- a/docs/entity-manager-api.md +++ b/docs/entity-manager-api.md @@ -173,16 +173,11 @@ const [timbers, timbersCount] = await manager.findAndCount(User, { firstName: "T const users = await manager.findByIds(User, [1, 2, 3]); ``` -* `findOne` - Finds first entity that matches given find options. - -```typescript -const timber = await manager.findOne(User, { firstName: "Timber" }); -``` - -* `findOneById` - Finds entity with given id. +* `findOne` - Finds first entity that matches given id or find options. ```typescript const user = await manager.findOne(User, 1); +const timber = await manager.findOne(User, { firstName: "Timber" }); ``` * `clear` - Clears all the data from the given table (truncates/drops it). diff --git a/docs/example-with-express.md b/docs/example-with-express.md index a8489388f8..3f044fb935 100644 --- a/docs/example-with-express.md +++ b/docs/example-with-express.md @@ -213,7 +213,7 @@ createConnection().then(connection => { }); app.get("/users/:id", async function(req: Request, res: Response) { - return userRepository.findOneById(req.params.id); + return userRepository.findOne(req.params.id); }); app.post("/users", async function(req: Request, res: Response) { @@ -222,7 +222,7 @@ createConnection().then(connection => { }); app.delete("/users/:id", async function(req: Request, res: Response) { - return userRepository.removeById(req.params.id); + return userRepository.remove(req.params.id); }); // start express server diff --git a/docs/relational-query-builder.md b/docs/relational-query-builder.md index 71dad46176..26a14ef841 100644 --- a/docs/relational-query-builder.md +++ b/docs/relational-query-builder.md @@ -24,7 +24,7 @@ This code is equivalent to doing this: import {getManager} from "typeorm"; const postRepository = getRepository(Post); -const post = await postRepository.findOneById(1, { relations: ["categories"] }); +const post = await postRepository.findOne(1, { relations: ["categories"] }); post.categories.push(category); await postRepository.save(post); ``` @@ -110,7 +110,7 @@ To load those relations you can use following code: ```typescript import {getConnection} from "typeorm"; -const post = await getConnection().manager.findOneById(Post, 1); +const post = await getConnection().manager.findOne(Post, 1); post.categories = await getConnection() .createQueryBuilder() diff --git a/docs/repository-api.md b/docs/repository-api.md index fa0040d643..c0e580ad4c 100644 --- a/docs/repository-api.md +++ b/docs/repository-api.md @@ -175,16 +175,11 @@ const [timbers, timbersCount] = await repository.findAndCount({ firstName: "Timb const users = await repository.findByIds([1, 2, 3]); ``` -* `findOne` - Finds first entity that matches given find options. - -```typescript -const timber = await repository.findOne({ firstName: "Timber" }); -``` - -* `findOneById` - Finds entity with given id. +* `findOne` - Finds first entity that matches given id or find options. ```typescript const user = await repository.findOne(1); +const timber = await repository.findOne({ firstName: "Timber" }); ``` * `query` - Executes a raw SQL query. diff --git a/docs/working-with-entity-manager.md b/docs/working-with-entity-manager.md index 6e4bc1587d..f74282bfd0 100644 --- a/docs/working-with-entity-manager.md +++ b/docs/working-with-entity-manager.md @@ -8,9 +8,10 @@ Example how to use it: ```typescript import {getManager} from "typeorm"; +import {User} from "./entity/User"; const entityManager = getManager(); // you can also get it via getConnection().manager -const user = await entityManager.findOneById(1); +const user = await entityManager.findOne(User, 1); user.name = "Umed"; await entityManager.save(user); ``` \ No newline at end of file diff --git a/docs/working-with-repository.md b/docs/working-with-repository.md index a8a49004cc..869ad91c0d 100644 --- a/docs/working-with-repository.md +++ b/docs/working-with-repository.md @@ -11,7 +11,7 @@ import {getRepository} from "typeorm"; import {User} from "./entity/User"; const userRepository = getRepository(User); // you can also get it via getConnection().getRepository() or getManager().getRepository() -const user = await userRepository.findOneById(1); +const user = await userRepository.findOne(1); user.name = "Umed"; await userRepository.save(user); ``` diff --git a/sample/sample11-all-types-entity/app.ts b/sample/sample11-all-types-entity/app.ts index 9a1e3f33af..c3618bf597 100644 --- a/sample/sample11-all-types-entity/app.ts +++ b/sample/sample11-all-types-entity/app.ts @@ -77,7 +77,7 @@ createConnection(options).then(connection => { return postRepository.save(entity); }) .then(entity => { - return postRepository.findOneById(entity.id); + return postRepository.findOne(entity.id); }) .then(entity => { console.log("Entity is loaded: ", entity); diff --git a/sample/sample13-everywhere-abstraction/app.ts b/sample/sample13-everywhere-abstraction/app.ts index a4295ef28c..ea607b536f 100644 --- a/sample/sample13-everywhere-abstraction/app.ts +++ b/sample/sample13-everywhere-abstraction/app.ts @@ -60,7 +60,7 @@ createConnection(options).then(connection => { .save(post) .then(post => { console.log("Post has been saved"); - return postRepository.findOneById(post.id); + return postRepository.findOne(post.id); }) .then(loadedPost => { console.log("post is loaded: ", loadedPost); @@ -68,7 +68,7 @@ createConnection(options).then(connection => { }) .then(blog => { console.log("Blog has been saved"); - return blogRepository.findOneById(blog.id); + return blogRepository.findOne(blog.id); }) .then(loadedBlog => { console.log("blog is loaded: ", loadedBlog); diff --git a/sample/sample25-insert-from-inverse-side/app.ts b/sample/sample25-insert-from-inverse-side/app.ts index 09313a5d57..3c05834f71 100644 --- a/sample/sample25-insert-from-inverse-side/app.ts +++ b/sample/sample25-insert-from-inverse-side/app.ts @@ -20,24 +20,24 @@ createConnection(options).then(connection => { let postRepository = connection.getRepository(Post); let authorRepository = connection.getRepository(Author); - const authorPromise = authorRepository.findOneById(1).then(author => { + const authorPromise = authorRepository.findOne(1).then(author => { if (!author) { author = new Author(); author.name = "Umed"; return authorRepository.save(author).then(savedAuthor => { - return authorRepository.findOneById(1); + return authorRepository.findOne(1); }); } return author; }); - const postPromise = postRepository.findOneById(1).then(post => { + const postPromise = postRepository.findOne(1).then(post => { if (!post) { post = new Post(); post.title = "Hello post"; post.text = "This is post contents"; return postRepository.save(post).then(savedPost => { - return postRepository.findOneById(1); + return postRepository.findOne(1); }); } return post; diff --git a/sample/sample26-embedded-tables/app.ts b/sample/sample26-embedded-tables/app.ts index 9b915a65cb..6f22703851 100644 --- a/sample/sample26-embedded-tables/app.ts +++ b/sample/sample26-embedded-tables/app.ts @@ -34,7 +34,7 @@ createConnection(options).then(connection => { console.log("question has been saved: ", savedQuestion); // lets load it now: - return questionRepository.findOneById(savedQuestion.id); + return questionRepository.findOne(savedQuestion.id); }) .then(loadedQuestion => { console.log("question has been loaded: ", loadedQuestion); diff --git a/sample/sample27-composite-primary-keys/app.ts b/sample/sample27-composite-primary-keys/app.ts index 777d982308..1b0850abf4 100644 --- a/sample/sample27-composite-primary-keys/app.ts +++ b/sample/sample27-composite-primary-keys/app.ts @@ -28,7 +28,7 @@ createConnection(options).then(async connection => { console.log("Post has been saved: ", post); console.log("now loading the post: "); - const loadedPost = await postRepository.findOneById({ id: 1, type: "person" }); + const loadedPost = await postRepository.findOne({ id: 1, type: "person" }); console.log("loaded post: ", loadedPost); }, error => console.log("Error: ", error)); diff --git a/sample/sample28-single-table-inheritance/app.ts b/sample/sample28-single-table-inheritance/app.ts index 4e792c64e1..f30ab760e7 100644 --- a/sample/sample28-single-table-inheritance/app.ts +++ b/sample/sample28-single-table-inheritance/app.ts @@ -36,7 +36,7 @@ createConnection(options).then(async connection => { console.log("employee has been saved: ", employee); console.log("now loading the employee: "); - const loadedEmployee = await employeeRepository.findOneById(1); + const loadedEmployee = await employeeRepository.findOne(1); console.log("loaded employee: ", loadedEmployee); console.log("-----------------"); @@ -53,7 +53,7 @@ createConnection(options).then(async connection => { console.log("homesitter has been saved: ", homesitter); console.log("now loading the homesitter: "); - const loadedHomesitter = await homesitterRepository.findOneById(2); + const loadedHomesitter = await homesitterRepository.findOne(2); console.log("loaded homesitter: ", loadedHomesitter); console.log("-----------------"); @@ -70,23 +70,23 @@ createConnection(options).then(async connection => { console.log("student has been saved: ", student); console.log("now loading the student: "); - const loadedStudent = await studentRepository.findOneById(3); + const loadedStudent = await studentRepository.findOne(3); console.log("loaded student: ", loadedStudent); console.log("-----------------"); - const secondEmployee = await employeeRepository.findOneById(2); + const secondEmployee = await employeeRepository.findOne(2); console.log("Non exist employee: ", secondEmployee); - const thirdEmployee = await employeeRepository.findOneById(3); + const thirdEmployee = await employeeRepository.findOne(3); console.log("Non exist employee: ", thirdEmployee); console.log("-----------------"); - const secondHomesitter = await homesitterRepository.findOneById(1); + const secondHomesitter = await homesitterRepository.findOne(1); console.log("Non exist homesitter: ", secondHomesitter); - const thirdHomesitter = await homesitterRepository.findOneById(3); + const thirdHomesitter = await homesitterRepository.findOne(3); console.log("Non exist homesitter: ", thirdHomesitter); console.log("-----------------"); - const secondStudent = await studentRepository.findOneById(1); + const secondStudent = await studentRepository.findOne(1); console.log("Non exist student: ", secondStudent); - const thirdStudent = await studentRepository.findOneById(2); + const thirdStudent = await studentRepository.findOne(2); console.log("Non exist student: ", thirdStudent); diff --git a/sample/sample29-class-table-inheritance/app.ts b/sample/sample29-class-table-inheritance/app.ts index 95a6af9b5b..7d91db779e 100644 --- a/sample/sample29-class-table-inheritance/app.ts +++ b/sample/sample29-class-table-inheritance/app.ts @@ -42,7 +42,7 @@ createConnection(options).then(async connection => { console.log("employee has been updated: ", employee); console.log("now loading the employee: "); - const loadedEmployee = (await employeeRepository.findOneById(1))!; + const loadedEmployee = (await employeeRepository.findOne(1))!; console.log("loaded employee: ", loadedEmployee); loadedEmployee.firstName = "dima"; @@ -69,7 +69,7 @@ createConnection(options).then(async connection => { console.log("homesitter has been saved: ", homesitter); console.log("now loading the homesitter: "); - const loadedHomesitter = await homesitterRepository.findOneById(2); + const loadedHomesitter = await homesitterRepository.findOne(2); console.log("loaded homesitter: ", loadedHomesitter); console.log("-----------------"); @@ -86,23 +86,23 @@ createConnection(options).then(async connection => { console.log("student has been saved: ", student); console.log("now loading the student: "); - const loadedStudent = await studentRepository.findOneById(3); + const loadedStudent = await studentRepository.findOne(3); console.log("loaded student: ", loadedStudent); console.log("-----------------"); - const secondEmployee = await employeeRepository.findOneById(2); + const secondEmployee = await employeeRepository.findOne(2); console.log("Non exist employee: ", secondEmployee); - const thirdEmployee = await employeeRepository.findOneById(3); + const thirdEmployee = await employeeRepository.findOne(3); console.log("Non exist employee: ", thirdEmployee); console.log("-----------------"); - const secondHomesitter = await homesitterRepository.findOneById(1); + const secondHomesitter = await homesitterRepository.findOne(1); console.log("Non exist homesitter: ", secondHomesitter); - const thirdHomesitter = await homesitterRepository.findOneById(3); + const thirdHomesitter = await homesitterRepository.findOne(3); console.log("Non exist homesitter: ", thirdHomesitter); console.log("-----------------"); - const secondStudent = await studentRepository.findOneById(1); + const secondStudent = await studentRepository.findOne(1); console.log("Non exist student: ", secondStudent); - const thirdStudent = await studentRepository.findOneById(2); + const thirdStudent = await studentRepository.findOne(2); console.log("Non exist student: ", thirdStudent);*/ }).catch(error => console.log("Error: ", error)); diff --git a/sample/sample5-subscribers/app.ts b/sample/sample5-subscribers/app.ts index ca4e8eeadc..6fb1616706 100644 --- a/sample/sample5-subscribers/app.ts +++ b/sample/sample5-subscribers/app.ts @@ -41,7 +41,7 @@ createConnection(options).then(connection => { .save(post) .then(post => { console.log("Post has been saved"); - return postRepository.findOneById(post.id); + return postRepository.findOne(post.id); }) .then(loadedPost => { console.log("---------------------------"); diff --git a/sample/sample6-abstract-table/app.ts b/sample/sample6-abstract-table/app.ts index 201ce5d8dc..eb8d690220 100644 --- a/sample/sample6-abstract-table/app.ts +++ b/sample/sample6-abstract-table/app.ts @@ -55,7 +55,7 @@ createConnection(options).then(connection => { .save(post) .then(post => { console.log("Post has been saved"); - return postRepository.findOneById(post.id); + return postRepository.findOne(post.id); }) .then(loadedPost => { console.log("post is loaded: ", loadedPost); @@ -63,7 +63,7 @@ createConnection(options).then(connection => { }) .then(blog => { console.log("Blog has been saved"); - return blogRepository.findOneById(blog.id); + return blogRepository.findOne(blog.id); }) .then(loadedBlog => { console.log("blog is loaded: ", loadedBlog); diff --git a/sample/sample9-entity-listeners/app.ts b/sample/sample9-entity-listeners/app.ts index 3c869a2f4c..c3b52b4e3c 100644 --- a/sample/sample9-entity-listeners/app.ts +++ b/sample/sample9-entity-listeners/app.ts @@ -39,7 +39,7 @@ createConnection(options).then(connection => { .then(post => { console.log("Post has been saved"); console.log("---------------------------"); - return postRepository.findOneById(post.id); + return postRepository.findOne(post.id); }) .then(loadedPost => { console.log("post is loaded. Its uid is " + loadedPost!.uid); diff --git a/src/commands/InitCommand.ts b/src/commands/InitCommand.ts index 727683ce32..ee871cac84 100644 --- a/src/commands/InitCommand.ts +++ b/src/commands/InitCommand.ts @@ -270,7 +270,7 @@ export class UserController { } async one(request: Request, response: Response, next: NextFunction) { - return this.userRepository.findOneById(request.params.id); + return this.userRepository.findOne(request.params.id); } async save(request: Request, response: Response, next: NextFunction) { diff --git a/src/entity-manager/EntityManager.ts b/src/entity-manager/EntityManager.ts index 4e0add0a85..0cec4cc038 100644 --- a/src/entity-manager/EntityManager.ts +++ b/src/entity-manager/EntityManager.ts @@ -27,6 +27,7 @@ import {TreeRepositoryNotSupportedError} from "../error/TreeRepositoryNotSupport import {EntityMetadata} from "../metadata/EntityMetadata"; import {QueryPartialEntity} from "../query-builder/QueryPartialEntity"; import {EntityPersitor} from "../persistence/EntityPersitor"; +import {ObjectID} from "../driver/mongodb/typings"; /** * Entity manager supposed to work with any entity, automatically find its repository and call its methods, @@ -521,7 +522,7 @@ export class EntityManager { /** * Finds first entity that matches given find options. */ - findOne(entityClass: ObjectType|string, id?: string|number|Date, options?: FindOneOptions): Promise; + findOne(entityClass: ObjectType|string, id?: string|number|Date|ObjectID, options?: FindOneOptions): Promise; /** * Finds first entity that matches given find options. @@ -536,7 +537,7 @@ export class EntityManager { /** * Finds first entity that matches given conditions. */ - findOne(entityClass: ObjectType|string, idOrOptionsOrConditions: string|number|Date|FindOneOptions|Partial, maybeOptions?: FindOneOptions): Promise { + findOne(entityClass: ObjectType|string, idOrOptionsOrConditions: string|number|Date|ObjectID|FindOneOptions|Partial, maybeOptions?: FindOneOptions): Promise { const metadata = this.connection.getMetadata(entityClass); let alias: string = metadata.name; diff --git a/src/platform/PlatformTools.ts b/src/platform/PlatformTools.ts index c92fb4d6d1..06c67f80cd 100644 --- a/src/platform/PlatformTools.ts +++ b/src/platform/PlatformTools.ts @@ -115,15 +115,15 @@ export class PlatformTools { * Logging functions needed by AdvancedConsoleLogger */ static logInfo(prefix: string, info: any) { - console.log(chalk.gray.underline(prefix) + " ", info); + console.log(chalk.gray.underline(prefix), info); } static logError(prefix: string, error: any) { - console.log(chalk.underline.red(prefix) + " ", error); + console.log(chalk.underline.red(prefix), error); } static logWarn(prefix: string, warning: any) { - console.log(chalk.underline.yellow(prefix) + " ", warning); + console.log(chalk.underline.yellow(prefix), warning); } static log(message: string) { diff --git a/src/repository/BaseEntity.ts b/src/repository/BaseEntity.ts index 12c6edaae6..30becb76ca 100644 --- a/src/repository/BaseEntity.ts +++ b/src/repository/BaseEntity.ts @@ -8,6 +8,7 @@ import {FindManyOptions} from "../find-options/FindManyOptions"; import {Connection} from "../connection/Connection"; import {ObjectType} from "../common/ObjectType"; import {SelectQueryBuilder} from "../query-builder/SelectQueryBuilder"; +import {ObjectID} from "../driver/mongodb/typings"; /** * Base abstract entity for all entities, used in ActiveRecord patterns. @@ -271,6 +272,11 @@ export class BaseEntity { return (this as any).getRepository().findByIds(ids, optionsOrConditions as any); } + /** + * Finds first entity that matches given options. + */ + static findOne(this: ObjectType, id?: string|number|Date|ObjectID, options?: FindOneOptions): Promise; + /** * Finds first entity that matches given options. */ @@ -279,7 +285,7 @@ export class BaseEntity { /** * Finds first entity that matches given conditions. */ - static findOne(this: ObjectType, conditions?: DeepPartial): Promise; + static findOne(this: ObjectType, conditions?: DeepPartial, options?: FindOneOptions): Promise; /** * Finds first entity that matches given conditions. @@ -291,18 +297,24 @@ export class BaseEntity { /** * Finds entity by given id. * Optionally find options can be applied. + * + * @deprecated use findOne instead */ static findOneById(this: ObjectType, id: any, options?: FindOneOptions): Promise; /** * Finds entity by given id. * Optionally conditions can be applied. + * + * @deprecated use findOne instead */ static findOneById(this: ObjectType, id: any, conditions?: DeepPartial): Promise; /** * Finds entity by given id. * Optionally find options or conditions can be applied. + * + * @deprecated use findOne instead */ static findOneById(this: ObjectType, id: any, optionsOrConditions?: FindOneOptions|DeepPartial): Promise { return (this as any).getRepository().findOneById(id, optionsOrConditions as any); diff --git a/src/repository/MongoRepository.ts b/src/repository/MongoRepository.ts index 705905baa5..3c11a00458 100644 --- a/src/repository/MongoRepository.ts +++ b/src/repository/MongoRepository.ts @@ -24,7 +24,7 @@ import { InsertWriteOpResult, MapReduceOptions, MongoCountPreferences, - MongodbIndexOptions, + MongodbIndexOptions, ObjectID, OrderedBulkOperation, ParallelCollectionScanOptions, ReadPreference, @@ -97,7 +97,7 @@ export class MongoRepository extends Repository|Partial, maybeOptions?: FindOneOptions): Promise { + findOne(optionsOrConditions?: string|number|Date|ObjectID|FindOneOptions|Partial, maybeOptions?: FindOneOptions): Promise { return this.manager.findOne(this.metadata.target, optionsOrConditions as any, maybeOptions as any); } diff --git a/src/repository/Repository.ts b/src/repository/Repository.ts index b6605eb4ad..df6f27804e 100644 --- a/src/repository/Repository.ts +++ b/src/repository/Repository.ts @@ -8,6 +8,7 @@ import {RemoveOptions} from "./RemoveOptions"; import {EntityManager} from "../entity-manager/EntityManager"; import {QueryRunner} from "../query-runner/QueryRunner"; import {SelectQueryBuilder} from "../query-builder/SelectQueryBuilder"; +import {ObjectID} from "../driver/mongodb/typings"; /** * Repository is supposed to work with your entity objects. Find entities, insert, update, delete, etc. @@ -294,7 +295,7 @@ export class Repository { /** * Finds first entity that matches given options. */ - findOne(id?: string|number|Date): Promise; + findOne(id?: string|number|Date|ObjectID, options?: FindOneOptions): Promise; /** * Finds first entity that matches given options. @@ -304,16 +305,32 @@ export class Repository { /** * Finds first entity that matches given conditions. */ - findOne(conditions?: DeepPartial): Promise; + findOne(conditions?: DeepPartial, options?: FindOneOptions): Promise; /** * Finds first entity that matches given conditions. */ - findOne(optionsOrConditions?: string|number|Date|FindOneOptions|DeepPartial): Promise { + findOne(optionsOrConditions?: string|number|Date|ObjectID|FindOneOptions|DeepPartial): Promise { return this.manager.findOne(this.metadata.target, optionsOrConditions as any); } - // todo: deprecate findOneById method, use findOne instead + /** + * Executes a raw SQL query and returns a raw database results. + * Raw query execution is supported only by relational databases (MongoDB is not supported). + */ + async query(query: string, parameters?: any[]): Promise { + return this.manager.query(query, parameters); + } + + /** + * Clears all the data from the given table/collection (truncates/drops it). + * + * Note: this method uses TRUNCATE and may not work as you expect in transactions on some platforms. + * @see https://stackoverflow.com/a/5972738/925151 + */ + async clear(): Promise { + return this.manager.clear(this.metadata.target); + } /** * Finds entity by given id. @@ -341,22 +358,4 @@ export class Repository { return this.manager.findOneById(this.metadata.target, id, optionsOrConditions as any); } - /** - * Executes a raw SQL query and returns a raw database results. - * Raw query execution is supported only by relational databases (MongoDB is not supported). - */ - async query(query: string, parameters?: any[]): Promise { - return this.manager.query(query, parameters); - } - - /** - * Clears all the data from the given table/collection (truncates/drops it). - * - * Note: this method uses TRUNCATE and may not work as you expect in transactions on some platforms. - * @see https://stackoverflow.com/a/5972738/925151 - */ - async clear(): Promise { - return this.manager.clear(this.metadata.target); - } - } \ No newline at end of file diff --git a/test/functional/columns/getters-setters/columns-getters-setters.ts b/test/functional/columns/getters-setters/columns-getters-setters.ts index f45c1eb7ee..8bc37fe568 100644 --- a/test/functional/columns/getters-setters/columns-getters-setters.ts +++ b/test/functional/columns/getters-setters/columns-getters-setters.ts @@ -24,7 +24,7 @@ describe("columns > getters and setters", () => { await postRepository.save(post); // check if title is a value applied by a setter - const loadedPost1 = await postRepository.findOneById(1); + const loadedPost1 = await postRepository.findOne(1); expect(loadedPost1!.title).to.be.equal("bye"); // try to load a column by its value diff --git a/test/functional/columns/no-select/columns-no-select.ts b/test/functional/columns/no-select/columns-no-select.ts index 32fb21b192..aca0983346 100644 --- a/test/functional/columns/no-select/columns-no-select.ts +++ b/test/functional/columns/no-select/columns-no-select.ts @@ -25,7 +25,7 @@ describe("columns > no-selection functionality", () => { await postRepository.save(post); // check if all columns are updated except for readonly columns - const loadedPost = await postRepository.findOneById(1); + const loadedPost = await postRepository.findOne(1); expect(loadedPost!.title).to.be.equal("About columns"); expect(loadedPost!.text).to.be.equal("Some text about columns"); expect(loadedPost!.authorName).to.be.undefined; diff --git a/test/functional/columns/readonly/columns-readonly.ts b/test/functional/columns/readonly/columns-readonly.ts index 82f8e48a4b..7e5d9101ef 100644 --- a/test/functional/columns/readonly/columns-readonly.ts +++ b/test/functional/columns/readonly/columns-readonly.ts @@ -32,7 +32,7 @@ describe("columns > readonly functionality", () => { await postRepository.save(post); // check if all columns are updated except for readonly columns - const loadedPost = await postRepository.findOneById(1); + const loadedPost = await postRepository.findOne(1); expect(loadedPost!.title).to.be.equal("About columns1"); expect(loadedPost!.text).to.be.equal("Some text about columns1"); expect(loadedPost!.authorName).to.be.equal("Umed1"); diff --git a/test/functional/columns/value-transformer/value-transformer.ts b/test/functional/columns/value-transformer/value-transformer.ts index d15a9b8147..c3f5597738 100644 --- a/test/functional/columns/value-transformer/value-transformer.ts +++ b/test/functional/columns/value-transformer/value-transformer.ts @@ -30,7 +30,7 @@ describe("columns > value-transformer functionality", () => { await postRepository.save(post); // check if all columns are updated except for readonly columns - const loadedPost = await postRepository.findOneById(1); + const loadedPost = await postRepository.findOne(1); expect(loadedPost!.title).to.be.equal("About columns1"); expect(loadedPost!.tags).to.deep.eq(["very", "simple"]); diff --git a/test/functional/connection-manager/connection-manager.ts b/test/functional/connection-manager/connection-manager.ts index 6a4b6afc12..a58e5a6311 100644 --- a/test/functional/connection-manager/connection-manager.ts +++ b/test/functional/connection-manager/connection-manager.ts @@ -128,7 +128,7 @@ describe("ConnectionManager", () => { // recreate connection and find previously saved post connection = await connectionManager.create(options).connect(); - const loadedPost = (await connection.manager.findOneById(Post, 1))!; + const loadedPost = (await connection.manager.findOne(Post, 1))!; loadedPost.should.be.instanceof(Post); loadedPost.should.be.eql({ id: 1, title: "Hello post" }); await connection.close(); @@ -151,7 +151,7 @@ describe("ConnectionManager", () => { // recreate connection and find previously saved post connection = await connectionManager.create(options).connect(); - const loadedPost = await connection.manager.findOneById(Post, 1); + const loadedPost = await connection.manager.findOne(Post, 1); expect(loadedPost).to.be.undefined; await connection.close(); }); @@ -173,7 +173,7 @@ describe("ConnectionManager", () => { // recreate connection and find previously saved post connection = await connectionManager.createAndConnect(options); - const loadedPost = await connection.manager.findOneById(Post, 1); + const loadedPost = await connection.manager.findOne(Post, 1); expect(loadedPost).to.be.undefined; await connection.close(); @@ -196,7 +196,7 @@ describe("ConnectionManager", () => { // recreate connection and find previously saved post connection = await connectionManager.createAndConnect(options); - const loadedPost = await connection.manager.findOneById(Post, 1); + const loadedPost = await connection.manager.findOne(Post, 1); expect(loadedPost).to.be.undefined; await connection.close(); });*/ diff --git a/test/functional/connection/connection.ts b/test/functional/connection/connection.ts index 1e58255e93..b8fa039bb9 100644 --- a/test/functional/connection/connection.ts +++ b/test/functional/connection/connection.ts @@ -179,10 +179,10 @@ describe("Connection", () => { const post = new Post(); post.title = "new post"; await postRepository.save(post); - const loadedPost = await postRepository.findOneById(post.id); + const loadedPost = await postRepository.findOne(post.id); expect(loadedPost).to.be.eql(post); await connection.synchronize(true); - const againLoadedPost = await postRepository.findOneById(post.id); + const againLoadedPost = await postRepository.findOne(post.id); expect(againLoadedPost).to.be.empty; }))); diff --git a/test/functional/database-schema/column-types/mssql/column-types-mssql.ts b/test/functional/database-schema/column-types/mssql/column-types-mssql.ts index a040e15b9d..d4e5bb5701 100644 --- a/test/functional/database-schema/column-types/mssql/column-types-mssql.ts +++ b/test/functional/database-schema/column-types/mssql/column-types-mssql.ts @@ -66,7 +66,7 @@ describe("database schema > column types > mssql", () => { post.simpleArray = ["A", "B", "C"]; await postRepository.save(post); - const loadedPost = (await postRepository.findOneById(1))!; + const loadedPost = (await postRepository.findOne(1))!; loadedPost.id.should.be.equal(post.id); loadedPost.name.should.be.equal(post.name); loadedPost.bit.should.be.equal(post.bit); @@ -172,7 +172,7 @@ describe("database schema > column types > mssql", () => { post.datetimeoffset = new Date(); await postRepository.save(post); - const loadedPost = (await postRepository.findOneById(1))!; + const loadedPost = (await postRepository.findOne(1))!; loadedPost.id.should.be.equal(post.id); loadedPost.char.should.be.equal(post.char); loadedPost.varchar.should.be.equal(post.varchar); @@ -243,7 +243,7 @@ describe("database schema > column types > mssql", () => { post.datetime.setMilliseconds(0); // set milliseconds to zero because the SQL Server datetime type only has a 1/300 ms (~3.33̅ ms) resolution await postRepository.save(post); - const loadedPost = (await postRepository.findOneById(1))!; + const loadedPost = (await postRepository.findOne(1))!; loadedPost.id.should.be.equal(post.id); loadedPost.name.should.be.equal(post.name); loadedPost.bit.should.be.equal(post.bit); diff --git a/test/functional/database-schema/column-types/mysql/column-types-mysql.ts b/test/functional/database-schema/column-types/mysql/column-types-mysql.ts index 3705904c28..90e3197c7a 100644 --- a/test/functional/database-schema/column-types/mysql/column-types-mysql.ts +++ b/test/functional/database-schema/column-types/mysql/column-types-mysql.ts @@ -61,7 +61,7 @@ describe("database schema > column types > mysql", () => { post.simpleArray = ["A", "B", "C"]; await postRepository.save(post); - const loadedPost = (await postRepository.findOneById(1))!; + const loadedPost = (await postRepository.findOne(1))!; loadedPost.id.should.be.equal(post.id); loadedPost.name.should.be.equal(post.name); loadedPost.int.should.be.equal(post.int); @@ -169,7 +169,7 @@ describe("database schema > column types > mysql", () => { post.time = "15:30:00.256"; await postRepository.save(post); - const loadedPost = (await postRepository.findOneById(1))!; + const loadedPost = (await postRepository.findOne(1))!; loadedPost.id.should.be.equal(post.id); loadedPost.name.should.be.equal(post.name); loadedPost.int.should.be.equal(post.int); @@ -238,7 +238,7 @@ describe("database schema > column types > mysql", () => { post.datetime.setMilliseconds(0); // set milliseconds to zero, because if datetime type specified without precision, milliseconds won't save in database await postRepository.save(post); - const loadedPost = (await postRepository.findOneById(1))!; + const loadedPost = (await postRepository.findOne(1))!; loadedPost.id.should.be.equal(post.id); loadedPost.name.should.be.equal(post.name); loadedPost.boolean.should.be.equal(post.boolean); diff --git a/test/functional/database-schema/column-types/postgres/column-types-postgres.ts b/test/functional/database-schema/column-types/postgres/column-types-postgres.ts index 2b2de51ec7..c32983f5bf 100644 --- a/test/functional/database-schema/column-types/postgres/column-types-postgres.ts +++ b/test/functional/database-schema/column-types/postgres/column-types-postgres.ts @@ -82,7 +82,7 @@ describe("database schema > column types > postgres", () => { post.simpleArray = ["A", "B", "C"]; await postRepository.save(post); - const loadedPost = (await postRepository.findOneById(1))!; + const loadedPost = (await postRepository.findOne(1))!; loadedPost.id.should.be.equal(post.id); loadedPost.name.should.be.equal(post.name); loadedPost.integer.should.be.equal(post.integer); @@ -220,7 +220,7 @@ describe("database schema > column types > postgres", () => { post.timeWithTimeZone = "15:30:13.27801+05"; await postRepository.save(post); - const loadedPost = (await postRepository.findOneById(1))!; + const loadedPost = (await postRepository.findOne(1))!; loadedPost.id.should.be.equal(post.id); loadedPost.numeric.should.be.equal(post.numeric); loadedPost.decimal.should.be.equal(post.decimal); @@ -274,7 +274,7 @@ describe("database schema > column types > postgres", () => { post.datetime.setMilliseconds(0); await postRepository.save(post); - const loadedPost = (await postRepository.findOneById(1))!; + const loadedPost = (await postRepository.findOne(1))!; loadedPost.id.should.be.equal(post.id); loadedPost.name.should.be.equal(post.name); loadedPost.bit.should.be.equal(post.bit); diff --git a/test/functional/database-schema/column-types/sqlite/column-types-sqlite.ts b/test/functional/database-schema/column-types/sqlite/column-types-sqlite.ts index 44bf36467e..617c02c67e 100644 --- a/test/functional/database-schema/column-types/sqlite/column-types-sqlite.ts +++ b/test/functional/database-schema/column-types/sqlite/column-types-sqlite.ts @@ -59,7 +59,7 @@ describe("database schema > column types > sqlite", () => { post.simpleArray = ["A", "B", "C"]; await postRepository.save(post); - const loadedPost = (await postRepository.findOneById(1))!; + const loadedPost = (await postRepository.findOne(1))!; loadedPost.id.should.be.equal(post.id); loadedPost.name.should.be.equal(post.name); loadedPost.int.should.be.equal(post.int); @@ -141,7 +141,7 @@ describe("database schema > column types > sqlite", () => { post.datetime.setMilliseconds(0); await postRepository.save(post); - const loadedPost = (await postRepository.findOneById(1))!; + const loadedPost = (await postRepository.findOne(1))!; loadedPost.id.should.be.equal(post.id); loadedPost.name.should.be.equal(post.name); loadedPost.boolean.should.be.equal(post.boolean); diff --git a/test/functional/database-schema/mssql-parameters/mssql-parameters.ts b/test/functional/database-schema/mssql-parameters/mssql-parameters.ts index 0ec8d03398..121b26a8e7 100644 --- a/test/functional/database-schema/mssql-parameters/mssql-parameters.ts +++ b/test/functional/database-schema/mssql-parameters/mssql-parameters.ts @@ -29,7 +29,7 @@ describe("database schema > mssql-parameters", () => { post1.text = "This is post"; await postRepository.save(post1); - let loadedPost1 = (await postRepository.findOneById(1))!; + let loadedPost1 = (await postRepository.findOne(1))!; loadedPost1.id.should.be.equal(post1.id); loadedPost1.name.should.be.equal(post1.name); @@ -40,12 +40,12 @@ describe("database schema > mssql-parameters", () => { loadedPost1.text = "This is updated post"; await postRepository.save(loadedPost1); - loadedPost1 = (await postRepository.findOneById(1))!; + loadedPost1 = (await postRepository.findOne(1))!; loadedPost1.name.should.be.equal("Updated Post #1"); loadedPost1.text.should.be.equal("This is updated post"); await postRepository.remove(loadedPost1); - loadedPost1 = (await postRepository.findOneById(1))!; + loadedPost1 = (await postRepository.findOne(1))!; expect(loadedPost1).to.not.exist; const post2 = new Post(); @@ -60,7 +60,7 @@ describe("database schema > mssql-parameters", () => { .values(post2) .execute(); - let loadedPost2 = (await postRepository.findOneById(2))!; + let loadedPost2 = (await postRepository.findOne(2))!; loadedPost2.id.should.be.equal(post2.id); loadedPost2.name.should.be.equal(post2.name); loadedPost2.category.should.be.equal(post2.category); @@ -72,7 +72,7 @@ describe("database schema > mssql-parameters", () => { .where("id = :id", { id: 2 }) .execute(); - loadedPost2 = (await postRepository.findOneById(2))!; + loadedPost2 = (await postRepository.findOne(2))!; loadedPost2.name.should.be.equal("Updated Post #2"); await connection.createQueryBuilder() @@ -81,7 +81,7 @@ describe("database schema > mssql-parameters", () => { .where("id = :id", { id: "2" }) .execute(); - loadedPost2 = (await postRepository.findOneById(2))!; + loadedPost2 = (await postRepository.findOne(2))!; expect(loadedPost2).to.not.exist; }))); diff --git a/test/functional/decorators/embedded/query-builder-embedded.ts b/test/functional/decorators/embedded/query-builder-embedded.ts index 70bd029808..f4d6b0c8a2 100644 --- a/test/functional/decorators/embedded/query-builder-embedded.ts +++ b/test/functional/decorators/embedded/query-builder-embedded.ts @@ -29,7 +29,7 @@ describe("decorators > embedded", () => { await postRepository.save(post); // now load it - const loadedPost = (await postRepository.findOneById(1))!; + const loadedPost = (await postRepository.findOne(1))!; loadedPost.id.should.be.equal(1); loadedPost.title.should.be.equal("Hello post"); loadedPost.text.should.be.equal("This is text about the post"); diff --git a/test/functional/driver/convert-to-entity/convert-to-entity.ts b/test/functional/driver/convert-to-entity/convert-to-entity.ts index 66210ee393..6fc6008cc6 100644 --- a/test/functional/driver/convert-to-entity/convert-to-entity.ts +++ b/test/functional/driver/convert-to-entity/convert-to-entity.ts @@ -22,7 +22,7 @@ describe("driver > convert raw results to entity", () => { await postRepository.save(post); - const loadedPost = await postRepository.findOneById(1); + const loadedPost = await postRepository.findOne(1); if (loadedPost) { expect(loadedPost.isNew).to.be.equal(null); } @@ -36,7 +36,7 @@ describe("driver > convert raw results to entity", () => { await postRepository.save(post); - const loadedPost = await postRepository.findOneById(1); + const loadedPost = await postRepository.findOne(1); if (loadedPost) { expect(loadedPost.isNew).to.be.equal(true); } @@ -50,7 +50,7 @@ describe("driver > convert raw results to entity", () => { await postRepository.save(post); - const loadedPost = await postRepository.findOneById(1); + const loadedPost = await postRepository.findOne(1); if (loadedPost) { expect(loadedPost.isNew).to.be.equal(false); } diff --git a/test/functional/embedded/basic-functionality/basic-functionality.ts b/test/functional/embedded/basic-functionality/basic-functionality.ts index 16395f4afe..fc3e53ac85 100644 --- a/test/functional/embedded/basic-functionality/basic-functionality.ts +++ b/test/functional/embedded/basic-functionality/basic-functionality.ts @@ -30,7 +30,7 @@ describe("embedded > basic functionality", () => { await postRepository.save(post); // now load it - const loadedPost = (await postRepository.findOneById(1))!; + const loadedPost = (await postRepository.findOne(1))!; loadedPost.id.should.be.equal(1); loadedPost.title.should.be.equal("Hello post"); loadedPost.text.should.be.equal("This is text about the post"); @@ -46,7 +46,7 @@ describe("embedded > basic functionality", () => { await postRepository.save(loadedPost); // now check it - const loadedPost2 = (await postRepository.findOneById(1))!; + const loadedPost2 = (await postRepository.findOne(1))!; loadedPost2.id.should.be.equal(1); loadedPost2.title.should.be.equal("Hello post"); loadedPost2.text.should.be.equal("This is text about the post"); @@ -59,7 +59,7 @@ describe("embedded > basic functionality", () => { await postRepository.remove(loadedPost2); // now check it - const loadedPost3 = (await postRepository.findOneById(1))!; + const loadedPost3 = (await postRepository.findOne(1))!; expect(loadedPost3).to.be.undefined; }))); diff --git a/test/functional/embedded/multiple-primary-columns-with-nested-embed/multiple-primary-columns-with-nested-embed.ts b/test/functional/embedded/multiple-primary-columns-with-nested-embed/multiple-primary-columns-with-nested-embed.ts index 98e3f91ef9..550cde3140 100644 --- a/test/functional/embedded/multiple-primary-columns-with-nested-embed/multiple-primary-columns-with-nested-embed.ts +++ b/test/functional/embedded/multiple-primary-columns-with-nested-embed/multiple-primary-columns-with-nested-embed.ts @@ -85,7 +85,7 @@ describe("embedded > multiple-primary-columns-with-nested-embed", () => { } )); - const loadedPost = (await postRepository.findOneById({ id: 1, counters: { code: 1, subcounters: { version: 1 } } }))!; + const loadedPost = (await postRepository.findOne({ id: 1, counters: { code: 1, subcounters: { version: 1 } } }))!; expect(loadedPost.should.be.eql( { id: 1, @@ -107,7 +107,7 @@ describe("embedded > multiple-primary-columns-with-nested-embed", () => { loadedPost.counters.subcounters.watches += 1; await postRepository.save(loadedPost); - const loadedPost2 = (await postRepository.findOneById({ id: 1, counters: { code: 1, subcounters: { version: 1 } } }))!; + const loadedPost2 = (await postRepository.findOne({ id: 1, counters: { code: 1, subcounters: { version: 1 } } }))!; expect(loadedPost2.should.be.eql( { id: 1, diff --git a/test/functional/embedded/multiple-primary-columns/multiple-primary-columns.ts b/test/functional/embedded/multiple-primary-columns/multiple-primary-columns.ts index e96047b1d5..611ad12bb4 100644 --- a/test/functional/embedded/multiple-primary-columns/multiple-primary-columns.ts +++ b/test/functional/embedded/multiple-primary-columns/multiple-primary-columns.ts @@ -50,14 +50,14 @@ describe("embedded > multiple-primary-column", () => { expect(loadedPosts[1].title).to.be.equal("About airplanes"); expect(loadedPosts[1].counters.should.be.eql({ code: 2, comments: 2, favorites: 3, likes: 4 })); - const loadedPost = (await postRepository.findOneById({ id: 1, counters: { code: 1 } }))!; + const loadedPost = (await postRepository.findOne({ id: 1, counters: { code: 1 } }))!; expect(loadedPost.title).to.be.equal("About cars"); expect(loadedPost.counters.should.be.eql({ code: 1, comments: 1, favorites: 2, likes: 3 })); loadedPost.counters.favorites += 1; await postRepository.save(loadedPost); - const loadedPost2 = (await postRepository.findOneById({ id: 1, counters: { code: 1 } }))!; + const loadedPost2 = (await postRepository.findOne({ id: 1, counters: { code: 1 } }))!; expect(loadedPost.title).to.be.equal("About cars"); expect(loadedPost.counters.should.be.eql({ code: 1, comments: 1, favorites: 3, likes: 3 })); diff --git a/test/functional/embedded/outer-primary-column/outer-primary-column.ts b/test/functional/embedded/outer-primary-column/outer-primary-column.ts index 5f65aaf104..073d086ab2 100644 --- a/test/functional/embedded/outer-primary-column/outer-primary-column.ts +++ b/test/functional/embedded/outer-primary-column/outer-primary-column.ts @@ -50,14 +50,14 @@ describe("embedded > outer-primary-column", () => { expect(loadedPosts[1].title).to.be.equal("About airplanes"); expect(loadedPosts[1].counters.should.be.eql({ code: 2, comments: 2, favorites: 3, likes: 4 })); - const loadedPost = (await postRepository.findOneById(1))!; + const loadedPost = (await postRepository.findOne(1))!; expect(loadedPost.title).to.be.equal("About cars"); expect(loadedPost.counters.should.be.eql({ code: 1, comments: 1, favorites: 2, likes: 3 })); loadedPost.counters.favorites += 1; await postRepository.save(loadedPost); - const loadedPost2 = (await postRepository.findOneById(1))!; + const loadedPost2 = (await postRepository.findOne(1))!; expect(loadedPost.title).to.be.equal("About cars"); expect(loadedPost.counters.should.be.eql({ code: 1, comments: 1, favorites: 3, likes: 3 })); diff --git a/test/functional/embedded/prefix/embedded-prefix.ts b/test/functional/embedded/prefix/embedded-prefix.ts index 402567c329..766a9d57d9 100644 --- a/test/functional/embedded/prefix/embedded-prefix.ts +++ b/test/functional/embedded/prefix/embedded-prefix.ts @@ -29,7 +29,7 @@ describe("embedded > prefix functionality", () => { await postRepository.save(post); // now load it - const loadedPost = (await postRepository.findOneById(1))!; + const loadedPost = (await postRepository.findOne(1))!; loadedPost.id.should.be.equal(1); loadedPost.title.should.be.equal("Hello post"); loadedPost.text.should.be.equal("This is text about the post"); diff --git a/test/functional/entity-model/entity-model.ts b/test/functional/entity-model/entity-model.ts index 50d658c51e..84ac59848b 100644 --- a/test/functional/entity-model/entity-model.ts +++ b/test/functional/entity-model/entity-model.ts @@ -23,7 +23,7 @@ describe("entity-model", () => { post.text = "Huge discussion how good or bad ActiveRecord is."; await post.save(); - const loadedPost = await Post.findOneById(1); + const loadedPost = await Post.findOne(1); loadedPost!.should.be.instanceOf(Post); loadedPost!.id.should.be.eql(1); diff --git a/test/functional/json/jsonb.ts b/test/functional/json/jsonb.ts index 157de68e7f..762a578b28 100644 --- a/test/functional/json/jsonb.ts +++ b/test/functional/json/jsonb.ts @@ -30,7 +30,7 @@ describe("jsonb type", () => { let record = new Record(); record.data = { foo: "bar" }; let persistedRecord = await recordRepo.save(record); - let foundRecord = await recordRepo.findOneById(persistedRecord.id); + let foundRecord = await recordRepo.findOne(persistedRecord.id); expect(foundRecord).to.be.not.undefined; expect(foundRecord!.data.foo).to.eq("bar"); }))); @@ -40,7 +40,7 @@ describe("jsonb type", () => { let record = new Record(); record.data = "foo"; let persistedRecord = await recordRepo.save(record); - let foundRecord = await recordRepo.findOneById(persistedRecord.id); + let foundRecord = await recordRepo.findOne(persistedRecord.id); expect(foundRecord).to.be.not.undefined; expect(foundRecord!.data).to.be.a("string"); expect(foundRecord!.data).to.eq("foo"); @@ -51,7 +51,7 @@ describe("jsonb type", () => { let record = new Record(); record.data = [1, "2", { a: 3 }]; let persistedRecord = await recordRepo.save(record); - let foundRecord = await recordRepo.findOneById(persistedRecord.id); + let foundRecord = await recordRepo.findOne(persistedRecord.id); expect(foundRecord).to.be.not.undefined; expect(foundRecord!.data).to.deep.include.members([1, "2", { a: 3 }]); }))); diff --git a/test/functional/mongodb/basic/repository-actions/mongodb-repository-actions.ts b/test/functional/mongodb/basic/repository-actions/mongodb-repository-actions.ts index 96a00e2a31..02ca6d884a 100644 --- a/test/functional/mongodb/basic/repository-actions/mongodb-repository-actions.ts +++ b/test/functional/mongodb/basic/repository-actions/mongodb-repository-actions.ts @@ -102,8 +102,8 @@ describe("mongodb > basic repository actions", () => { } await postRepository.save(posts); - // assert findOneById method - const loadedPost1 = await postRepository.findOneById(post1.id); + // assert.findOne method + const loadedPost1 = await postRepository.findOne(post1.id); expect(loadedPost1!.id).to.be.eql(post1.id); expect(loadedPost1!.title).to.be.equal("First Post"); expect(loadedPost1!.text).to.be.equal("Everything about first post"); @@ -231,7 +231,7 @@ describe("mongodb > basic repository actions", () => { post2.text = "Everything about second post"; await postRepository.save(post2); - const loadedPost1 = await postRepository.findOneById(post1.id); + const loadedPost1 = await postRepository.findOne(post1.id); await postRepository.remove(loadedPost1!); await postRepository.remove(post2); diff --git a/test/functional/persistence/basic-functionality/persistence-basic-functionality.ts b/test/functional/persistence/basic-functionality/persistence-basic-functionality.ts index cb94970e44..f2bd0689f1 100644 --- a/test/functional/persistence/basic-functionality/persistence-basic-functionality.ts +++ b/test/functional/persistence/basic-functionality/persistence-basic-functionality.ts @@ -53,14 +53,14 @@ describe("persistence > basic functionality", function() { const user = new User("Hello User"); await connection.manager.save([post, category, user]); - await connection.manager.findOneById(Post, 1).should.eventually.eql({ id: 1, title: "Hello Post" }); - await connection.manager.findOneById(Category, 1).should.eventually.eql({ id: 1, name: "Hello Category" }); - await connection.manager.findOneById(User, 1).should.eventually.eql({ id: 1, name: "Hello User" }); + await connection.manager.findOne(Post, 1).should.eventually.eql({ id: 1, title: "Hello Post" }); + await connection.manager.findOne(Category, 1).should.eventually.eql({ id: 1, name: "Hello Category" }); + await connection.manager.findOne(User, 1).should.eventually.eql({ id: 1, name: "Hello User" }); await connection.manager.remove([post, category, user]); - await connection.manager.findOneById(Post, 1).should.eventually.be.undefined; - await connection.manager.findOneById(Category, 1).should.eventually.be.undefined; - await connection.manager.findOneById(User, 1).should.eventually.be.undefined; + await connection.manager.findOne(Post, 1).should.eventually.be.undefined; + await connection.manager.findOne(Category, 1).should.eventually.be.undefined; + await connection.manager.findOne(User, 1).should.eventually.be.undefined; }))); }); diff --git a/test/functional/persistence/custom-column-names/persistence-custom-column-names.ts b/test/functional/persistence/custom-column-names/persistence-custom-column-names.ts index c3ad0ed3d1..6737857a9f 100644 --- a/test/functional/persistence/custom-column-names/persistence-custom-column-names.ts +++ b/test/functional/persistence/custom-column-names/persistence-custom-column-names.ts @@ -69,7 +69,7 @@ describe("persistence > custom-column-names", function() { // load a post before(function() { return postRepository - .findOneById(1, { join: { alias: "post", leftJoinAndSelect: { category: "post.category" } }}) + .findOne(1, { join: { alias: "post", leftJoinAndSelect: { category: "post.category" } }}) .then(post => loadedPost = post!); }); @@ -104,7 +104,7 @@ describe("persistence > custom-column-names", function() { // load a post before(function() { return postRepository - .findOneById(1, { join: { alias: "post", leftJoinAndSelect: { category: "post.category" } } }) + .findOne(1, { join: { alias: "post", leftJoinAndSelect: { category: "post.category" } } }) .then(post => loadedPost = post!); }); @@ -134,7 +134,7 @@ describe("persistence > custom-column-names", function() { // load a post before(function() { return postRepository - .findOneById(1, { join: { alias: "post", leftJoinAndSelect: { category: "post.category" } }}) + .findOne(1, { join: { alias: "post", leftJoinAndSelect: { category: "post.category" } }}) .then(post => loadedPost = post!); }); @@ -182,7 +182,7 @@ describe("persistence > custom-column-names", function() { // load a post before(function() { return postRepository - .findOneById(1, { join: { alias: "post", leftJoinAndSelect: { category: "post.category", metadata: "category.metadata" } } }) + .findOne(1, { join: { alias: "post", leftJoinAndSelect: { category: "post.category", metadata: "category.metadata" } } }) .then(post => loadedPost = post!); }); @@ -227,7 +227,7 @@ describe("persistence > custom-column-names", function() { // load a post before(function() { return postRepository - .findOneById(1, { join: { alias: "post", leftJoinAndSelect: { category: "post.category", metadata: "category.metadata" } } }) + .findOne(1, { join: { alias: "post", leftJoinAndSelect: { category: "post.category", metadata: "category.metadata" } } }) .then(post => loadedPost = post!); }); diff --git a/test/functional/persistence/entity-updation/entity/PostComplex.ts b/test/functional/persistence/entity-updation/entity/PostComplex.ts new file mode 100644 index 0000000000..7cffd71f3c --- /dev/null +++ b/test/functional/persistence/entity-updation/entity/PostComplex.ts @@ -0,0 +1,18 @@ +import {Entity} from "../../../../../src/decorator/entity/Entity"; +import {Column} from "../../../../../src/decorator/columns/Column"; +import {PrimaryGeneratedColumn} from "../../../../../src/decorator/columns/PrimaryGeneratedColumn"; +import {PostEmbedded} from "./PostEmbedded"; + +@Entity() +export class PostComplex { + + @PrimaryGeneratedColumn("uuid") + firstId: number; + + @Column() + text: string; + + @Column(type => PostEmbedded) + embed: PostEmbedded; + +} \ No newline at end of file diff --git a/test/functional/persistence/entity-updation/entity/PostDefaultValues.ts b/test/functional/persistence/entity-updation/entity/PostDefaultValues.ts new file mode 100644 index 0000000000..a9017d68d1 --- /dev/null +++ b/test/functional/persistence/entity-updation/entity/PostDefaultValues.ts @@ -0,0 +1,14 @@ +import {Entity} from "../../../../../src/decorator/entity/Entity"; +import {PrimaryGeneratedColumn} from "../../../../../src/decorator/columns/PrimaryGeneratedColumn"; +import {Column} from "../../../../../src/decorator/columns/Column"; + +@Entity() +export class PostDefaultValues { + + @PrimaryGeneratedColumn() + id: number; + + @Column() + text: string; + +} \ No newline at end of file diff --git a/test/functional/persistence/entity-updation/entity/PostEmbedded.ts b/test/functional/persistence/entity-updation/entity/PostEmbedded.ts new file mode 100644 index 0000000000..cf2f0c38bf --- /dev/null +++ b/test/functional/persistence/entity-updation/entity/PostEmbedded.ts @@ -0,0 +1,20 @@ +import {PrimaryColumn} from "../../../../../src/decorator/columns/PrimaryColumn"; +import {UpdateDateColumn} from "../../../../../src/decorator/columns/UpdateDateColumn"; +import {CreateDateColumn} from "../../../../../src/decorator/columns/CreateDateColumn"; +import {VersionColumn} from "../../../../../src/decorator/columns/VersionColumn"; + +export class PostEmbedded { + + @PrimaryColumn("uuid") + secondId: number; + + @CreateDateColumn() + createDate: Date; + + @UpdateDateColumn() + updateDate: Date; + + @VersionColumn() + version: number; + +} \ No newline at end of file diff --git a/test/functional/persistence/entity-updation/entity/PostIncrement.ts b/test/functional/persistence/entity-updation/entity/PostIncrement.ts new file mode 100644 index 0000000000..e2458ab508 --- /dev/null +++ b/test/functional/persistence/entity-updation/entity/PostIncrement.ts @@ -0,0 +1,14 @@ +import {Entity} from "../../../../../src/decorator/entity/Entity"; +import {Column} from "../../../../../src/decorator/columns/Column"; +import {PrimaryGeneratedColumn} from "../../../../../src/decorator/columns/PrimaryGeneratedColumn"; + +@Entity() +export class PostIncrement { + + @PrimaryGeneratedColumn() + id: number; + + @Column() + text: string; + +} \ No newline at end of file diff --git a/test/functional/persistence/entity-updation/entity/PostMultiplePrimaryKeys.ts b/test/functional/persistence/entity-updation/entity/PostMultiplePrimaryKeys.ts new file mode 100644 index 0000000000..d94b72074f --- /dev/null +++ b/test/functional/persistence/entity-updation/entity/PostMultiplePrimaryKeys.ts @@ -0,0 +1,17 @@ +import {Entity} from "../../../../../src/decorator/entity/Entity"; +import {Column} from "../../../../../src/decorator/columns/Column"; +import {PrimaryColumn} from "../../../../../src/decorator/columns/PrimaryColumn"; + +@Entity() +export class PostMultiplePrimaryKeys { + + @PrimaryColumn() + firstId: number; + + @PrimaryColumn() + secondId: number; + + @Column() + text: string; + +} \ No newline at end of file diff --git a/test/functional/persistence/entity-updation/entity/PostSpecialColumns.ts b/test/functional/persistence/entity-updation/entity/PostSpecialColumns.ts new file mode 100644 index 0000000000..257bca71a6 --- /dev/null +++ b/test/functional/persistence/entity-updation/entity/PostSpecialColumns.ts @@ -0,0 +1,26 @@ +import {Entity} from "../../../../../src/decorator/entity/Entity"; +import {PrimaryGeneratedColumn} from "../../../../../src/decorator/columns/PrimaryGeneratedColumn"; +import {CreateDateColumn} from "../../../../../src/decorator/columns/CreateDateColumn"; +import {UpdateDateColumn} from "../../../../../src/decorator/columns/UpdateDateColumn"; +import {Column} from "../../../../../src/decorator/columns/Column"; +import {VersionColumn} from "../../../../../src/decorator/columns/VersionColumn"; + +@Entity() +export class PostSpecialColumns { + + @PrimaryGeneratedColumn() + id: number; + + @Column() + title: string; + + @CreateDateColumn() + createDate: Date; + + @UpdateDateColumn() + updateDate: Date; + + @VersionColumn() + version: number; + +} \ No newline at end of file diff --git a/test/functional/persistence/entity-updation/entity/PostUuid.ts b/test/functional/persistence/entity-updation/entity/PostUuid.ts new file mode 100644 index 0000000000..14abd7f43e --- /dev/null +++ b/test/functional/persistence/entity-updation/entity/PostUuid.ts @@ -0,0 +1,14 @@ +import {Entity} from "../../../../../src/decorator/entity/Entity"; +import {Column} from "../../../../../src/decorator/columns/Column"; +import {PrimaryGeneratedColumn} from "../../../../../src/decorator/columns/PrimaryGeneratedColumn"; + +@Entity() +export class PostUuid { + + @PrimaryGeneratedColumn("uuid") + id: number; + + @Column() + text: string; + +} \ No newline at end of file diff --git a/test/functional/persistence/entity-updation/persistence-entity-updation.ts b/test/functional/persistence/entity-updation/persistence-entity-updation.ts new file mode 100644 index 0000000000..d8ef416092 --- /dev/null +++ b/test/functional/persistence/entity-updation/persistence-entity-updation.ts @@ -0,0 +1,28 @@ +import "reflect-metadata"; +import {Connection} from "../../../../src/connection/Connection"; +import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils"; + +describe("persistence > entity updation", () => { + + let connections: Connection[]; + before(async () => connections = await createTestingConnections({ __dirname })); + beforeEach(() => reloadTestingDatabases(connections)); + after(() => closeTestingConnections(connections)); + + it("should update generated auto-increment id after saving", () => Promise.all(connections.map(async connection => { + + }))); + + it("should update generated uuid after saving", () => Promise.all(connections.map(async connection => { + + }))); + + it("should update default values after saving", () => Promise.all(connections.map(async connection => { + + }))); + + it("should update special columns saving", () => Promise.all(connections.map(async connection => { + + }))); + +}); diff --git a/test/functional/persistence/many-to-many/persistence-many-to-many.ts b/test/functional/persistence/many-to-many/persistence-many-to-many.ts index e3c52724e7..b3744ca102 100644 --- a/test/functional/persistence/many-to-many/persistence-many-to-many.ts +++ b/test/functional/persistence/many-to-many/persistence-many-to-many.ts @@ -50,7 +50,7 @@ describe("persistence > many-to-many", function() { await userRepository.save(newUser); // load a post - const loadedUser = await userRepository.findOneById(1, { + const loadedUser = await userRepository.findOne(1, { join: { alias: "user", leftJoinAndSelect: { post: "user.post", categories: "post.categories" } @@ -95,7 +95,7 @@ describe("persistence > many-to-many", function() { await userRepository.save(newUser); // load a post - const loadedUser1 = await userRepository.findOneById(1, { + const loadedUser1 = await userRepository.findOne(1, { join: { alias: "user", leftJoinAndSelect: { post: "user.post", categories: "post.categories" } @@ -113,7 +113,7 @@ describe("persistence > many-to-many", function() { await userRepository.save(newUser); // load a post - const loadedUser2 = await userRepository.findOneById(1, { + const loadedUser2 = await userRepository.findOne(1, { join: { alias: "user", leftJoinAndSelect: { post: "user.post", categories: "post.categories" } @@ -159,7 +159,7 @@ describe("persistence > many-to-many", function() { await userRepository.save(newUser); // load a post - const loadedUser1 = await userRepository.findOneById(1, { + const loadedUser1 = await userRepository.findOne(1, { join: { alias: "user", leftJoinAndSelect: { post: "user.post", categories: "post.categories" } @@ -177,7 +177,7 @@ describe("persistence > many-to-many", function() { await userRepository.save(newUser); // load a post - const loadedUser2 = await userRepository.findOneById(1, { + const loadedUser2 = await userRepository.findOne(1, { join: { alias: "user", leftJoinAndSelect: { post: "user.post", categories: "post.categories" } @@ -222,7 +222,7 @@ describe("persistence > many-to-many", function() { await userRepository.save(newUser); // load a post - const loadedUser1 = await userRepository.findOneById(1, { + const loadedUser1 = await userRepository.findOne(1, { join: { alias: "user", leftJoinAndSelect: { post: "user.post", categories: "post.categories" } @@ -240,7 +240,7 @@ describe("persistence > many-to-many", function() { await userRepository.save(newUser); // load a post - const loadedUser2 = await userRepository.findOneById(1, { + const loadedUser2 = await userRepository.findOne(1, { join: { alias: "user", leftJoinAndSelect: { post: "user.post", categories: "post.categories" } diff --git a/test/functional/persistence/many-to-one-bi-directional/persistence-many-to-one-bi-directional.ts b/test/functional/persistence/many-to-one-bi-directional/persistence-many-to-one-bi-directional.ts index 78e34b88e5..3ac37687fe 100644 --- a/test/functional/persistence/many-to-one-bi-directional/persistence-many-to-one-bi-directional.ts +++ b/test/functional/persistence/many-to-one-bi-directional/persistence-many-to-one-bi-directional.ts @@ -26,7 +26,7 @@ describe("persistence > many-to-one bi-directional relation", function() { category.post = post; await connection.manager.save(category); - const loadedCategory = await connection.manager.findOneById(Category, 1, { relations: ["post"] }); + const loadedCategory = await connection.manager.findOne(Category, 1, { relations: ["post"] }); expect(loadedCategory).not.to.be.empty; loadedCategory!.should.be.eql({ id: 1, name: "Hello Category", post: { id: 1, title: "Hello Post" } }); }))); @@ -37,7 +37,7 @@ describe("persistence > many-to-one bi-directional relation", function() { category.post = post; await connection.manager.save(category); - const loadedCategory = await connection.manager.findOneById(Category, 1, { relations: ["post"] }); + const loadedCategory = await connection.manager.findOne(Category, 1, { relations: ["post"] }); expect(loadedCategory).not.to.be.empty; loadedCategory!.should.be.eql({ id: 1, name: "Hello Category", post: { id: 1, title: "Hello Post" } }); }))); @@ -55,7 +55,7 @@ describe("persistence > many-to-one bi-directional relation", function() { // save once again, just for fun await connection.manager.save(category); - const loadedCategory1 = await connection.manager.findOneById(Category, 1, { relations: ["post"] }); + const loadedCategory1 = await connection.manager.findOne(Category, 1, { relations: ["post"] }); expect(loadedCategory1).not.to.be.empty; loadedCategory1!.should.be.eql({ id: 1, name: "Hello Category", post: { id: 1, title: "Updated post" } }); @@ -63,7 +63,7 @@ describe("persistence > many-to-one bi-directional relation", function() { (loadedCategory1!.post as Post).title = "Again Updated post"; await connection.manager.save(loadedCategory1); - const loadedCategory2 = await connection.manager.findOneById(Category, 1, { relations: ["post"] }); + const loadedCategory2 = await connection.manager.findOne(Category, 1, { relations: ["post"] }); expect(loadedCategory2).not.to.be.empty; loadedCategory2!.should.be.eql({ id: 1, name: "Hello Category", post: { id: 1, title: "Again Updated post" } }); }))); @@ -78,7 +78,7 @@ describe("persistence > many-to-one bi-directional relation", function() { await connection.manager.save(category); // load and check if it was correctly saved - const loadedCategory1 = await connection.manager.findOneById(Category, 1, { relations: ["post"] }); + const loadedCategory1 = await connection.manager.findOne(Category, 1, { relations: ["post"] }); expect(loadedCategory1).not.to.be.empty; loadedCategory1!.should.be.eql({ id: 1, name: "Hello Category", post: { id: 1, title: "Hello Post" } }); @@ -86,11 +86,11 @@ describe("persistence > many-to-one bi-directional relation", function() { loadedCategory1!.post = undefined; await connection.manager.save(loadedCategory1); - const loadedCategory2 = await connection.manager.findOneById(Category, 1, { relations: ["post"] }); + const loadedCategory2 = await connection.manager.findOne(Category, 1, { relations: ["post"] }); expect(loadedCategory2).not.to.be.empty; loadedCategory2!.should.be.eql({ id: 1, name: "Hello Category", post: { id: 1, title: "Hello Post" } }); - const loadedPost = await connection.manager.findOneById(Post, 1); + const loadedPost = await connection.manager.findOne(Post, 1); expect(loadedPost).not.to.be.empty; loadedPost!.should.be.eql({ id: 1, title: "Hello Post" }); }))); @@ -104,7 +104,7 @@ describe("persistence > many-to-one bi-directional relation", function() { category.post = post; await connection.manager.save(category); - const loadedCategory1 = await connection.manager.findOneById(Category, 1, { relations: ["post"] }); + const loadedCategory1 = await connection.manager.findOne(Category, 1, { relations: ["post"] }); expect(loadedCategory1).not.to.be.empty; loadedCategory1!.should.be.eql({ id: 1, name: "Hello Category", post: { id: 1, title: "Hello Post" } }); @@ -112,7 +112,7 @@ describe("persistence > many-to-one bi-directional relation", function() { loadedCategory1!.post = null; await connection.manager.save(loadedCategory1); - const loadedCategory2 = await connection.manager.findOneById(Category, 1, { relations: ["post"] }); + const loadedCategory2 = await connection.manager.findOne(Category, 1, { relations: ["post"] }); expect(loadedCategory2).not.to.be.empty; loadedCategory2!.should.be.eql({ id: 1, name: "Hello Category", post: null }); }))); @@ -126,7 +126,7 @@ describe("persistence > many-to-one bi-directional relation", function() { category.post = post; await connection.manager.save(category); - const loadedCategory1 = await connection.manager.findOneById(Category, 1, { relations: ["post"] }); + const loadedCategory1 = await connection.manager.findOne(Category, 1, { relations: ["post"] }); expect(loadedCategory1).not.to.be.empty; loadedCategory1!.should.be.eql({ id: 1, name: "Hello Category", post: { id: 1, title: "Hello Post" } }); @@ -134,7 +134,7 @@ describe("persistence > many-to-one bi-directional relation", function() { await connection.manager.remove(post); // now lets load category and make sure post isn't set there - const loadedCategory2 = await connection.manager.findOneById(Category, 1, { relations: ["post"] }); + const loadedCategory2 = await connection.manager.findOne(Category, 1, { relations: ["post"] }); expect(loadedCategory2).not.to.be.empty; loadedCategory2!.should.be.eql({ id: 1, name: "Hello Category", post: null }); }))); @@ -154,7 +154,7 @@ describe("persistence > many-to-one bi-directional relation", function() { await connection.manager.save(category); // check if category is saved with post set - const loadedCategory1 = await connection.manager.findOneById(Category, 1, { relations: ["post"] }); + const loadedCategory1 = await connection.manager.findOne(Category, 1, { relations: ["post"] }); expect(loadedCategory1).not.to.be.empty; loadedCategory1!.should.be.eql({ id: 1, name: "Hello Category", post: { id: 1, title: "Hello Post #1" } }); @@ -163,7 +163,7 @@ describe("persistence > many-to-one bi-directional relation", function() { await connection.manager.save(category); // and check again if category is saved with new post - const loadedCategory2 = await connection.manager.findOneById(Category, 1, { relations: ["post"] }); + const loadedCategory2 = await connection.manager.findOne(Category, 1, { relations: ["post"] }); expect(loadedCategory2).not.to.be.empty; loadedCategory2!.should.be.eql({ id: 1, name: "Hello Category", post: { id: 2, title: "Hello Post #2" } }); }))); diff --git a/test/functional/persistence/many-to-one-uni-directional/persistence-many-to-one-uni-directional.ts b/test/functional/persistence/many-to-one-uni-directional/persistence-many-to-one-uni-directional.ts index fa94aea33d..642d093dfe 100644 --- a/test/functional/persistence/many-to-one-uni-directional/persistence-many-to-one-uni-directional.ts +++ b/test/functional/persistence/many-to-one-uni-directional/persistence-many-to-one-uni-directional.ts @@ -24,7 +24,7 @@ describe("persistence > many-to-one uni-directional relation", function() { category.post = post; await connection.manager.save(category); - const loadedCategory = await connection.manager.findOneById(Category, 1, { relations: ["post"] }); + const loadedCategory = await connection.manager.findOne(Category, 1, { relations: ["post"] }); expect(loadedCategory).not.to.be.empty; loadedCategory!.should.be.eql({ id: 1, name: "Hello Category", post: { id: 1, title: "Hello Post" } }); }))); @@ -35,7 +35,7 @@ describe("persistence > many-to-one uni-directional relation", function() { category.post = post; await connection.manager.save(category); - const loadedCategory = await connection.manager.findOneById(Category, 1, { relations: ["post"] }); + const loadedCategory = await connection.manager.findOne(Category, 1, { relations: ["post"] }); expect(loadedCategory).not.to.be.empty; loadedCategory!.should.be.eql({ id: 1, name: "Hello Category", post: { id: 1, title: "Hello Post" } }); }))); @@ -53,7 +53,7 @@ describe("persistence > many-to-one uni-directional relation", function() { // save once again, just for fun await connection.manager.save(category); - const loadedCategory1 = await connection.manager.findOneById(Category, 1, { relations: ["post"] }); + const loadedCategory1 = await connection.manager.findOne(Category, 1, { relations: ["post"] }); expect(loadedCategory1).not.to.be.empty; loadedCategory1!.should.be.eql({ id: 1, name: "Hello Category", post: { id: 1, title: "Updated post" } }); @@ -61,7 +61,7 @@ describe("persistence > many-to-one uni-directional relation", function() { (loadedCategory1!.post as Post).title = "Again Updated post"; await connection.manager.save(loadedCategory1); - const loadedCategory2 = await connection.manager.findOneById(Category, 1, { relations: ["post"] }); + const loadedCategory2 = await connection.manager.findOne(Category, 1, { relations: ["post"] }); expect(loadedCategory2).not.to.be.empty; loadedCategory2!.should.be.eql({ id: 1, name: "Hello Category", post: { id: 1, title: "Again Updated post" } }); }))); @@ -76,7 +76,7 @@ describe("persistence > many-to-one uni-directional relation", function() { await connection.manager.save(category); // load and check if it was correctly saved - const loadedCategory1 = await connection.manager.findOneById(Category, 1, { relations: ["post"] }); + const loadedCategory1 = await connection.manager.findOne(Category, 1, { relations: ["post"] }); expect(loadedCategory1).not.to.be.empty; loadedCategory1!.should.be.eql({ id: 1, name: "Hello Category", post: { id: 1, title: "Hello Post" } }); @@ -84,11 +84,11 @@ describe("persistence > many-to-one uni-directional relation", function() { loadedCategory1!.post = undefined; await connection.manager.save(loadedCategory1); - const loadedCategory2 = await connection.manager.findOneById(Category, 1, { relations: ["post"] }); + const loadedCategory2 = await connection.manager.findOne(Category, 1, { relations: ["post"] }); expect(loadedCategory2).not.to.be.empty; loadedCategory2!.should.be.eql({ id: 1, name: "Hello Category", post: { id: 1, title: "Hello Post" } }); - const loadedPost = await connection.manager.findOneById(Post, 1); + const loadedPost = await connection.manager.findOne(Post, 1); expect(loadedPost).not.to.be.empty; loadedPost!.should.be.eql({ id: 1, title: "Hello Post" }); }))); @@ -102,7 +102,7 @@ describe("persistence > many-to-one uni-directional relation", function() { category.post = post; await connection.manager.save(category); - const loadedCategory1 = await connection.manager.findOneById(Category, 1, { relations: ["post"] }); + const loadedCategory1 = await connection.manager.findOne(Category, 1, { relations: ["post"] }); expect(loadedCategory1).not.to.be.empty; loadedCategory1!.should.be.eql({ id: 1, name: "Hello Category", post: { id: 1, title: "Hello Post" } }); @@ -110,7 +110,7 @@ describe("persistence > many-to-one uni-directional relation", function() { loadedCategory1!.post = null; await connection.manager.save(loadedCategory1); - const loadedCategory2 = await connection.manager.findOneById(Category, 1, { relations: ["post"] }); + const loadedCategory2 = await connection.manager.findOne(Category, 1, { relations: ["post"] }); expect(loadedCategory2).not.to.be.empty; loadedCategory2!.should.be.eql({ id: 1, name: "Hello Category", post: null }); }))); @@ -124,7 +124,7 @@ describe("persistence > many-to-one uni-directional relation", function() { category.post = post; await connection.manager.save(category); - const loadedCategory1 = await connection.manager.findOneById(Category, 1, { relations: ["post"] }); + const loadedCategory1 = await connection.manager.findOne(Category, 1, { relations: ["post"] }); expect(loadedCategory1).not.to.be.empty; loadedCategory1!.should.be.eql({ id: 1, name: "Hello Category", post: { id: 1, title: "Hello Post" } }); @@ -132,7 +132,7 @@ describe("persistence > many-to-one uni-directional relation", function() { await connection.manager.remove(post); // now lets load category and make sure post isn't set there - const loadedCategory2 = await connection.manager.findOneById(Category, 1, { relations: ["post"] }); + const loadedCategory2 = await connection.manager.findOne(Category, 1, { relations: ["post"] }); expect(loadedCategory2).not.to.be.empty; loadedCategory2!.should.be.eql({ id: 1, name: "Hello Category", post: null }); }))); @@ -152,7 +152,7 @@ describe("persistence > many-to-one uni-directional relation", function() { await connection.manager.save(category); // check if category is saved with post set - const loadedCategory1 = await connection.manager.findOneById(Category, 1, { relations: ["post"] }); + const loadedCategory1 = await connection.manager.findOne(Category, 1, { relations: ["post"] }); expect(loadedCategory1).not.to.be.empty; loadedCategory1!.should.be.eql({ id: 1, name: "Hello Category", post: { id: 1, title: "Hello Post #1" } }); @@ -161,7 +161,7 @@ describe("persistence > many-to-one uni-directional relation", function() { await connection.manager.save(category); // and check again if category is saved with new post - const loadedCategory2 = await connection.manager.findOneById(Category, 1, { relations: ["post"] }); + const loadedCategory2 = await connection.manager.findOne(Category, 1, { relations: ["post"] }); expect(loadedCategory2).not.to.be.empty; loadedCategory2!.should.be.eql({ id: 1, name: "Hello Category", post: { id: 2, title: "Hello Post #2" } }); }))); diff --git a/test/functional/persistence/null-and-default-behaviour/null-and-default-behaviour.ts b/test/functional/persistence/null-and-default-behaviour/null-and-default-behaviour.ts index a91cbb2026..62a190b4a9 100644 --- a/test/functional/persistence/null-and-default-behaviour/null-and-default-behaviour.ts +++ b/test/functional/persistence/null-and-default-behaviour/null-and-default-behaviour.ts @@ -23,7 +23,7 @@ describe("persistence > null and default behaviour", () => { post.title = "Category saved!"; await connection.manager.save(post); - const loadedPost = await connection.manager.findOneById(Post, 1); + const loadedPost = await connection.manager.findOne(Post, 1); expect(loadedPost).to.exist; loadedPost!.should.be.eql({ id: 1, @@ -38,7 +38,7 @@ describe("persistence > null and default behaviour", () => { const post = new Post(); await connection.manager.save(post); - const loadedPost = await connection.manager.findOneById(Post, 1); + const loadedPost = await connection.manager.findOne(Post, 1); expect(loadedPost).to.exist; loadedPost!.should.be.eql({ id: 1, @@ -54,7 +54,7 @@ describe("persistence > null and default behaviour", () => { post.title = null; await connection.manager.save(post); - const loadedPost = await connection.manager.findOneById(Post, 1); + const loadedPost = await connection.manager.findOne(Post, 1); expect(loadedPost).to.exist; loadedPost!.should.be.eql({ id: 1, @@ -73,7 +73,7 @@ describe("persistence > null and default behaviour", () => { post.title = undefined; await connection.manager.save(post); - const loadedPost = await connection.manager.findOneById(Post, 1); + const loadedPost = await connection.manager.findOne(Post, 1); expect(loadedPost).to.exist; loadedPost!.should.be.eql({ id: 1, @@ -92,7 +92,7 @@ describe("persistence > null and default behaviour", () => { post.title = null; await connection.manager.save(post); - const loadedPost = await connection.manager.findOneById(Post, 1); + const loadedPost = await connection.manager.findOne(Post, 1); expect(loadedPost).to.exist; loadedPost!.should.be.eql({ id: 1, diff --git a/test/functional/persistence/one-to-many/persistence-one-to-many.ts b/test/functional/persistence/one-to-many/persistence-one-to-many.ts index 5d61634092..1357075398 100644 --- a/test/functional/persistence/one-to-many/persistence-one-to-many.ts +++ b/test/functional/persistence/one-to-many/persistence-one-to-many.ts @@ -40,7 +40,7 @@ describe("persistence > one-to-many", function() { newPost.categories = [newCategory]; await postRepository.save(newPost); - const loadedPost = await postRepository.findOneById(1, { relations: ["categories"] }); + const loadedPost = await postRepository.findOne(1, { relations: ["categories"] }); expect(loadedPost!).not.to.be.empty; expect(loadedPost!.categories).not.to.be.empty; expect(loadedPost!.categories![0]).not.to.be.empty; @@ -60,7 +60,7 @@ describe("persistence > one-to-many", function() { newPost.categories = [newCategory]; await postRepository.save(newPost); - const loadedPost = await postRepository.findOneById(1, { relations: ["categories"] }); + const loadedPost = await postRepository.findOne(1, { relations: ["categories"] }); expect(loadedPost).not.to.be.empty; expect(loadedPost!.categories).not.to.be.empty; expect(loadedPost!.categories![0]).not.to.be.empty; @@ -88,7 +88,7 @@ describe("persistence > one-to-many", function() { newPost.categories = [firstNewCategory]; await postRepository.save(newPost); - const loadedPost = await postRepository.findOneById(1, { + const loadedPost = await postRepository.findOne(1, { join: { alias: "post", innerJoinAndSelect: { @@ -124,7 +124,7 @@ describe("persistence > one-to-many", function() { newPost.categories = []; await postRepository.save(newPost); - const loadedPost = await postRepository.findOneById(1, { + const loadedPost = await postRepository.findOne(1, { join: { alias: "post", leftJoinAndSelect: { @@ -158,7 +158,7 @@ describe("persistence > one-to-many", function() { newPost.categories = null; await postRepository.save(newPost); - const loadedPost = (await postRepository.findOneById(1, { + const loadedPost = (await postRepository.findOne(1, { join: { alias: "post", leftJoinAndSelect: { diff --git a/test/functional/persistence/partial-persist/partial-persist.ts b/test/functional/persistence/partial-persist/partial-persist.ts index 818f66c2cb..e2b8becc04 100644 --- a/test/functional/persistence/partial-persist/partial-persist.ts +++ b/test/functional/persistence/partial-persist/partial-persist.ts @@ -48,7 +48,7 @@ describe("persistence > partial persist", () => { await postRepository.save(newPost); // load a post - const loadedPost = await postRepository.findOneById(1, { + const loadedPost = await postRepository.findOne(1, { join: { alias: "post", leftJoinAndSelect: { @@ -71,7 +71,7 @@ describe("persistence > partial persist", () => { await postRepository.update({ title: "All about animals" }, { title: "All about bears" }); // now check if update worked as expected, title is updated and all other columns are not touched - const loadedPostAfterTitleUpdate = await postRepository.findOneById(1, { + const loadedPostAfterTitleUpdate = await postRepository.findOne(1, { join: { alias: "post", leftJoinAndSelect: { @@ -94,7 +94,7 @@ describe("persistence > partial persist", () => { await postRepository.update({ id: 1 }, { counters: { stars: 10 } }); // now check if update worked as expected, stars counter is updated and all other columns are not touched - const loadedPostAfterStarsUpdate = await postRepository.findOneById(1, { + const loadedPostAfterStarsUpdate = await postRepository.findOne(1, { join: { alias: "post", leftJoinAndSelect: { @@ -117,7 +117,7 @@ describe("persistence > partial persist", () => { await postRepository.save({ id: 1, categories: [{ id: 1, name: "Bears" }] }); // now check if update worked as expected, name of category is updated and all other columns are not touched - const loadedPostAfterCategoryUpdate = await postRepository.findOneById(1, { + const loadedPostAfterCategoryUpdate = await postRepository.findOne(1, { join: { alias: "post", leftJoinAndSelect: { diff --git a/test/functional/query-builder/relational/with-many/query-builder-relational-add-remove-many-to-many-inverse.ts b/test/functional/query-builder/relational/with-many/query-builder-relational-add-remove-many-to-many-inverse.ts index 4a1232944a..6e34da7871 100644 --- a/test/functional/query-builder/relational/with-many/query-builder-relational-add-remove-many-to-many-inverse.ts +++ b/test/functional/query-builder/relational/with-many/query-builder-relational-add-remove-many-to-many-inverse.ts @@ -47,13 +47,13 @@ describe("query builder > relational query builder > add and remove operations > .of(image1) .add(post1); - let loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["images"] }); + let loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["images"] }); expect(loadedPost1!.images).to.contain({ id: 1, url: "image #1" }); - let loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["images"] }); + let loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["images"] }); expect(loadedPost2!.images).to.be.empty; - let loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["images"] }); + let loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["images"] }); expect(loadedPost3!.images).to.be.empty; await connection @@ -62,13 +62,13 @@ describe("query builder > relational query builder > add and remove operations > .of(image1) .remove(post1); - loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["images"] }); + loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["images"] }); expect(loadedPost1!.images).to.not.contain({ id: 1, url: "image #1" }); - loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["images"] }); + loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["images"] }); expect(loadedPost2!.images).to.be.empty; - loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["images"] }); + loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["images"] }); expect(loadedPost3!.images).to.be.empty; }))); @@ -104,13 +104,13 @@ describe("query builder > relational query builder > add and remove operations > .of(2) // image id .add(2); // post id - let loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["images"] }); + let loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["images"] }); expect(loadedPost1!.images).to.be.empty; - let loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["images"] }); + let loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["images"] }); expect(loadedPost2!.images).to.contain({ id: 2, url: "image #2" }); - let loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["images"] }); + let loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["images"] }); expect(loadedPost3!.images).to.be.empty; await connection @@ -119,13 +119,13 @@ describe("query builder > relational query builder > add and remove operations > .of(2) // image id .remove(2); // post id - loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["images"] }); + loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["images"] }); expect(loadedPost1!.images).to.be.empty; - loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["images"] }); + loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["images"] }); expect(loadedPost2!.images).to.not.contain({ id: 2, url: "image #2" }); - loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["images"] }); + loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["images"] }); expect(loadedPost3!.images).to.be.empty; }))); @@ -161,13 +161,13 @@ describe("query builder > relational query builder > add and remove operations > .of({ id: 3 }) // image id .add({ id: 3 }); // post id - let loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["images"] }); + let loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["images"] }); expect(loadedPost1!.images).to.be.empty; - let loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["images"] }); + let loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["images"] }); expect(loadedPost2!.images).to.be.empty; - let loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["images"] }); + let loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["images"] }); expect(loadedPost3!.images).to.contain({ id: 3, url: "image #3" }); await connection @@ -176,13 +176,13 @@ describe("query builder > relational query builder > add and remove operations > .of({ id: 3 }) // image id .remove({ id: 3 }); // post id - loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["images"] }); + loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["images"] }); expect(loadedPost1!.images).to.be.empty; - loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["images"] }); + loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["images"] }); expect(loadedPost2!.images).to.be.empty; - loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["images"] }); + loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["images"] }); expect(loadedPost3!.images).to.not.contain({ id: 3, url: "image #3" }); }))); @@ -218,13 +218,13 @@ describe("query builder > relational query builder > add and remove operations > .of([{ id: 1 }, { id: 3 }]) // images .add({ id: 3 }); // post - let loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["images"] }); + let loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["images"] }); expect(loadedPost1!.images).to.be.empty; - let loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["images"] }); + let loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["images"] }); expect(loadedPost2!.images).to.be.empty; - let loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["images"] }); + let loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["images"] }); expect(loadedPost3!.images).to.contain({ id: 1, url: "image #1" }); expect(loadedPost3!.images).to.contain({ id: 3, url: "image #3" }); @@ -234,13 +234,13 @@ describe("query builder > relational query builder > add and remove operations > .of([{ id: 1 }, { id: 3 }]) // images .remove({ id: 3 }); // post - loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["images"] }); + loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["images"] }); expect(loadedPost1!.images).to.be.empty; - loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["images"] }); + loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["images"] }); expect(loadedPost2!.images).to.be.empty; - loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["images"] }); + loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["images"] }); expect(loadedPost3!.images).to.not.contain({ id: 1, url: "image #1" }); expect(loadedPost3!.images).to.not.contain({ id: 3, url: "image #3" }); }))); @@ -277,13 +277,13 @@ describe("query builder > relational query builder > add and remove operations > .of({ id: 3 }) // image .add([{ id: 1 }, { id: 3 }]); // posts - let loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["images"] }); + let loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["images"] }); expect(loadedPost1!.images).to.contain({ id: 3, url: "image #3" }); - let loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["images"] }); + let loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["images"] }); expect(loadedPost2!.images).to.be.empty; - let loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["images"] }); + let loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["images"] }); expect(loadedPost3!.images).to.contain({ id: 3, url: "image #3" }); await connection @@ -292,13 +292,13 @@ describe("query builder > relational query builder > add and remove operations > .of({ id: 3 }) // image .remove([{ id: 1 }, { id: 3 }]); // posts - loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["images"] }); + loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["images"] }); expect(loadedPost1!.images).to.not.contain({ id: 3, url: "image #3" }); - loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["images"] }); + loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["images"] }); expect(loadedPost2!.images).to.be.empty; - loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["images"] }); + loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["images"] }); expect(loadedPost3!.images).to.not.contain({ id: 3, url: "image #3" }); }))); diff --git a/test/functional/query-builder/relational/with-many/query-builder-relational-add-remove-many-to-many.ts b/test/functional/query-builder/relational/with-many/query-builder-relational-add-remove-many-to-many.ts index 91b09b3e50..e72d463ab3 100644 --- a/test/functional/query-builder/relational/with-many/query-builder-relational-add-remove-many-to-many.ts +++ b/test/functional/query-builder/relational/with-many/query-builder-relational-add-remove-many-to-many.ts @@ -47,13 +47,13 @@ describe("query builder > relational query builder > add and remove operations > .of(post1) .add(image1); - let loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["images"] }); + let loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["images"] }); expect(loadedPost1!.images).to.contain({ id: 1, url: "image #1" }); - let loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["images"] }); + let loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["images"] }); expect(loadedPost2!.images).to.be.empty; - let loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["images"] }); + let loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["images"] }); expect(loadedPost3!.images).to.be.empty; await connection @@ -62,13 +62,13 @@ describe("query builder > relational query builder > add and remove operations > .of(post1) .remove(image1); - loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["images"] }); + loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["images"] }); expect(loadedPost1!.images).to.not.contain({ id: 1, url: "image #1" }); - loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["images"] }); + loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["images"] }); expect(loadedPost2!.images).to.be.empty; - loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["images"] }); + loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["images"] }); expect(loadedPost3!.images).to.be.empty; }))); @@ -104,13 +104,13 @@ describe("query builder > relational query builder > add and remove operations > .of(2) // post id .add(2); // image id - let loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["images"] }); + let loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["images"] }); expect(loadedPost1!.images).to.be.empty; - let loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["images"] }); + let loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["images"] }); expect(loadedPost2!.images).to.contain({ id: 2, url: "image #2" }); - let loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["images"] }); + let loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["images"] }); expect(loadedPost3!.images).to.be.empty; await connection @@ -119,13 +119,13 @@ describe("query builder > relational query builder > add and remove operations > .of(2) // post id .remove(2); // image id - loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["images"] }); + loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["images"] }); expect(loadedPost1!.images).to.be.empty; - loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["images"] }); + loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["images"] }); expect(loadedPost2!.images).to.not.contain({ id: 2, url: "image #2" }); - loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["images"] }); + loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["images"] }); expect(loadedPost3!.images).to.be.empty; }))); @@ -161,13 +161,13 @@ describe("query builder > relational query builder > add and remove operations > .of({ id: 3 }) // post id .add({ id: 3 }); // image id - let loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["images"] }); + let loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["images"] }); expect(loadedPost1!.images).to.be.empty; - let loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["images"] }); + let loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["images"] }); expect(loadedPost2!.images).to.be.empty; - let loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["images"] }); + let loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["images"] }); expect(loadedPost3!.images).to.contain({ id: 3, url: "image #3" }); await connection @@ -176,13 +176,13 @@ describe("query builder > relational query builder > add and remove operations > .of({ id: 3 }) // post id .remove({ id: 3 }); // image id - loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["images"] }); + loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["images"] }); expect(loadedPost1!.images).to.be.empty; - loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["images"] }); + loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["images"] }); expect(loadedPost2!.images).to.be.empty; - loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["images"] }); + loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["images"] }); expect(loadedPost3!.images).to.not.contain({ id: 3, url: "image #3" }); }))); @@ -218,13 +218,13 @@ describe("query builder > relational query builder > add and remove operations > .of([{ id: 1 }, { id: 3 }]) // posts .add({ id: 3 }); // image - let loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["images"] }); + let loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["images"] }); expect(loadedPost1!.images).to.contain({ id: 3, url: "image #3" }); - let loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["images"] }); + let loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["images"] }); expect(loadedPost2!.images).to.be.empty; - let loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["images"] }); + let loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["images"] }); expect(loadedPost3!.images).to.contain({ id: 3, url: "image #3" }); await connection @@ -233,13 +233,13 @@ describe("query builder > relational query builder > add and remove operations > .of([{ id: 1 }, { id: 3 }]) // posts .remove({ id: 3 }); // image - loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["images"] }); + loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["images"] }); expect(loadedPost1!.images).to.not.contain({ id: 3, url: "image #3" }); - loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["images"] }); + loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["images"] }); expect(loadedPost2!.images).to.be.empty; - loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["images"] }); + loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["images"] }); expect(loadedPost3!.images).to.not.not.contain({ id: 3, url: "image #3" }); }))); @@ -275,13 +275,13 @@ describe("query builder > relational query builder > add and remove operations > .of({ id: 3 }) // post .add([{ id: 1 }, { id: 3 }]); // images - let loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["images"] }); + let loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["images"] }); expect(loadedPost1!.images).to.be.empty; - let loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["images"] }); + let loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["images"] }); expect(loadedPost2!.images).to.be.empty; - let loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["images"] }); + let loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["images"] }); expect(loadedPost3!.images).to.contain({ id: 1, url: "image #1" }); expect(loadedPost3!.images).to.contain({ id: 3, url: "image #3" }); @@ -291,13 +291,13 @@ describe("query builder > relational query builder > add and remove operations > .of({ id: 3 }) // post .remove([{ id: 1 }, { id: 3 }]); // images - loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["images"] }); + loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["images"] }); expect(loadedPost1!.images).to.be.empty; - loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["images"] }); + loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["images"] }); expect(loadedPost2!.images).to.be.empty; - loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["images"] }); + loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["images"] }); expect(loadedPost3!.images).to.not.contain({ id: 1, url: "image #1" }); expect(loadedPost3!.images).to.not.contain({ id: 3, url: "image #3" }); }))); diff --git a/test/functional/query-builder/relational/with-many/query-builder-relational-add-remove-one-to-many.ts b/test/functional/query-builder/relational/with-many/query-builder-relational-add-remove-one-to-many.ts index 5ff5694f3e..2473ad7d37 100644 --- a/test/functional/query-builder/relational/with-many/query-builder-relational-add-remove-one-to-many.ts +++ b/test/functional/query-builder/relational/with-many/query-builder-relational-add-remove-one-to-many.ts @@ -47,13 +47,13 @@ describe("query builder > relational query builder > add operation > one to many .of(category1) .add(post1); - let loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["category"] }); + let loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["category"] }); expect(loadedPost1!.category).to.be.eql({ id: 1, name: "category #1" }); - let loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["category"] }); + let loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["category"] }); expect(loadedPost2!.category).to.be.undefined; - let loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["category"] }); + let loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["category"] }); expect(loadedPost3!.category).to.be.undefined; await connection @@ -62,13 +62,13 @@ describe("query builder > relational query builder > add operation > one to many .of(category1) .remove(post1); - loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["category"] }); + loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["category"] }); expect(loadedPost1!.category).to.be.undefined; - loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["category"] }); + loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["category"] }); expect(loadedPost2!.category).to.be.undefined; - loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["category"] }); + loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["category"] }); expect(loadedPost3!.category).to.be.undefined; }))); @@ -104,13 +104,13 @@ describe("query builder > relational query builder > add operation > one to many .of(2) // category id .add(2); // post id - let loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["category"] }); + let loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["category"] }); expect(loadedPost1!.category).to.be.undefined; - let loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["category"] }); + let loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["category"] }); expect(loadedPost2!.category).to.be.eql({ id: 2, name: "category #2" }); - let loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["category"] }); + let loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["category"] }); expect(loadedPost3!.category).to.be.undefined; await connection @@ -119,13 +119,13 @@ describe("query builder > relational query builder > add operation > one to many .of(2) // category id .remove(2); // post id - loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["category"] }); + loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["category"] }); expect(loadedPost1!.category).to.be.undefined; - loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["category"] }); + loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["category"] }); expect(loadedPost2!.category).to.be.undefined; - loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["category"] }); + loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["category"] }); expect(loadedPost3!.category).to.be.undefined; }))); @@ -161,13 +161,13 @@ describe("query builder > relational query builder > add operation > one to many .of({ id: 3 }) // category id .add({ id: 3 }); // post id - let loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["category"] }); + let loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["category"] }); expect(loadedPost1!.category).to.be.undefined; - let loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["category"] }); + let loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["category"] }); expect(loadedPost2!.category).to.be.undefined; - let loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["category"] }); + let loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["category"] }); expect(loadedPost3!.category).to.be.eql({ id: 3, name: "category #3" }); await connection @@ -176,13 +176,13 @@ describe("query builder > relational query builder > add operation > one to many .of({ id: 3 }) // category id .remove({ id: 3 }); // post id - loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["category"] }); + loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["category"] }); expect(loadedPost1!.category).to.be.undefined; - loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["category"] }); + loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["category"] }); expect(loadedPost2!.category).to.be.undefined; - loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["category"] }); + loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["category"] }); expect(loadedPost3!.category).to.be.undefined; }))); @@ -218,13 +218,13 @@ describe("query builder > relational query builder > add operation > one to many .of({ id: 3 }) // category .add([{ id: 1 }, { id: 3 }]); // posts - let loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["category"] }); + let loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["category"] }); expect(loadedPost1!.category).to.be.eql({ id: 3, name: "category #3" }); - let loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["category"] }); + let loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["category"] }); expect(loadedPost2!.category).to.be.undefined; - let loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["category"] }); + let loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["category"] }); expect(loadedPost3!.category).to.be.eql({ id: 3, name: "category #3" }); await connection @@ -233,13 +233,13 @@ describe("query builder > relational query builder > add operation > one to many .of({ id: 3 }) // category .remove([{ id: 1 }, { id: 3 }]); // posts - loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["category"] }); + loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["category"] }); expect(loadedPost1!.category).to.be.undefined; - loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["category"] }); + loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["category"] }); expect(loadedPost2!.category).to.be.undefined; - loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["category"] }); + loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["category"] }); expect(loadedPost3!.category).to.be.undefined; }))); @@ -276,7 +276,7 @@ describe("query builder > relational query builder > add operation > one to many .of(category3) // category .add(post2); // post - let loadedPost1 = await connection.manager.findOneById(Post, 2, { relations: ["category"] }); + let loadedPost1 = await connection.manager.findOne(Post, 2, { relations: ["category"] }); expect(loadedPost1!.category).to.be.eql({ id: 3, name: "category #3" }); // when nothing is specified nothing should be performed @@ -286,7 +286,7 @@ describe("query builder > relational query builder > add operation > one to many .of(category3) // category .addAndRemove([], []); // post - loadedPost1 = await connection.manager.findOneById(Post, 2, { relations: ["category"] }); + loadedPost1 = await connection.manager.findOne(Post, 2, { relations: ["category"] }); expect(loadedPost1!.category).to.be.eql({ id: 3, name: "category #3" }); // now add and remove =) @@ -296,7 +296,7 @@ describe("query builder > relational query builder > add operation > one to many .of(category3) // category .addAndRemove([post1, post3], [post2]); // post - const loadedCategory = await connection.manager.findOneById(Category, 3, { relations: ["posts"] }); + const loadedCategory = await connection.manager.findOne(Category, 3, { relations: ["posts"] }); expect(loadedCategory!.posts).to.contain({ id: 1, title: "post #1" }); expect(loadedCategory!.posts).to.not.contain({ id: 2, title: "post #2" }); expect(loadedCategory!.posts).to.contain({ id: 3, title: "post #3" }); diff --git a/test/functional/query-builder/relational/with-many/query-builder-relational-load-many.ts b/test/functional/query-builder/relational/with-many/query-builder-relational-load-many.ts index dbc6525f00..fd062f46f1 100644 --- a/test/functional/query-builder/relational/with-many/query-builder-relational-load-many.ts +++ b/test/functional/query-builder/relational/with-many/query-builder-relational-load-many.ts @@ -44,7 +44,7 @@ describe("query builder > relational query builder > add and remove operations > post3.images = [image1, image3]; await connection.manager.save(post3); - const loadedPost1 = await connection.manager.findOneById(Post, 1); + const loadedPost1 = await connection.manager.findOne(Post, 1); loadedPost1!.images = await connection .createQueryBuilder() .relation(Post, "images") @@ -85,7 +85,7 @@ describe("query builder > relational query builder > add and remove operations > post3.images = [image1, image3]; await connection.manager.save(post3); - const loadedPost1 = await connection.manager.findOneById(Post, 1); + const loadedPost1 = await connection.manager.findOne(Post, 1); loadedPost1!.images = await connection .createQueryBuilder() .relation(Post, "images") @@ -126,7 +126,7 @@ describe("query builder > relational query builder > add and remove operations > post3.images = [image1, image3]; await connection.manager.save(post3); - const loadedPost1 = await connection.manager.findOneById(Post, 1); + const loadedPost1 = await connection.manager.findOne(Post, 1); loadedPost1!.images = await connection .createQueryBuilder() .relation(Post, "images") diff --git a/test/functional/query-builder/relational/with-one/query-builder-relational-load-one.ts b/test/functional/query-builder/relational/with-one/query-builder-relational-load-one.ts index a9026ecb93..9c5c58d80c 100644 --- a/test/functional/query-builder/relational/with-one/query-builder-relational-load-one.ts +++ b/test/functional/query-builder/relational/with-one/query-builder-relational-load-one.ts @@ -44,7 +44,7 @@ describe("query builder > relational query builder > load operation > many-to-on post3.category = category1; await connection.manager.save(post3); - const loadedPost1 = await connection.manager.findOneById(Post, 1); + const loadedPost1 = await connection.manager.findOne(Post, 1); const loadedCategory1: Category = await connection .createQueryBuilder() .relation(Post, "category") @@ -54,7 +54,7 @@ describe("query builder > relational query builder > load operation > many-to-on expect(loadedPost1!.category).to.be.eql({ id: 3, name: "category #3" }); - const loadedPost2 = await connection.manager.findOneById(Post, 2); + const loadedPost2 = await connection.manager.findOne(Post, 2); const loadedCategory2: Category = await connection .createQueryBuilder() .relation(Post, "category") @@ -64,7 +64,7 @@ describe("query builder > relational query builder > load operation > many-to-on expect(loadedPost2!.category).to.be.eql({ id: 2, name: "category #2" }); - const loadedPost3 = await connection.manager.findOneById(Post, 3); + const loadedPost3 = await connection.manager.findOne(Post, 3); const loadedCategory3: Category = await connection .createQueryBuilder() .relation(Post, "category") @@ -104,7 +104,7 @@ describe("query builder > relational query builder > load operation > many-to-on post3.category = category1; await connection.manager.save(post3); - const loadedPost1 = await connection.manager.findOneById(Post, 1); + const loadedPost1 = await connection.manager.findOne(Post, 1); const loadedCategory1: Category = await connection .createQueryBuilder() .relation(Post, "category") @@ -114,7 +114,7 @@ describe("query builder > relational query builder > load operation > many-to-on expect(loadedPost1!.category).to.be.eql({ id: 3, name: "category #3" }); - const loadedPost2 = await connection.manager.findOneById(Post, 2); + const loadedPost2 = await connection.manager.findOne(Post, 2); const loadedCategory2: Category = await connection .createQueryBuilder() .relation(Post, "category") @@ -124,7 +124,7 @@ describe("query builder > relational query builder > load operation > many-to-on expect(loadedPost2!.category).to.be.eql({ id: 2, name: "category #2" }); - const loadedPost3 = await connection.manager.findOneById(Post, 3); + const loadedPost3 = await connection.manager.findOne(Post, 3); const loadedCategory3: Category = await connection .createQueryBuilder() .relation(Post, "category") @@ -164,7 +164,7 @@ describe("query builder > relational query builder > load operation > many-to-on post3.category = category1; await connection.manager.save(post3); - const loadedPost1 = await connection.manager.findOneById(Post, 1); + const loadedPost1 = await connection.manager.findOne(Post, 1); const loadedCategory1: Category = await connection .createQueryBuilder() .relation(Post, "category") @@ -174,7 +174,7 @@ describe("query builder > relational query builder > load operation > many-to-on expect(loadedPost1!.category).to.be.eql({ id: 3, name: "category #3" }); - const loadedPost2 = await connection.manager.findOneById(Post, 2); + const loadedPost2 = await connection.manager.findOne(Post, 2); const loadedCategory2: Category = await connection .createQueryBuilder() .relation(Post, "category") @@ -184,7 +184,7 @@ describe("query builder > relational query builder > load operation > many-to-on expect(loadedPost2!.category).to.be.eql({ id: 2, name: "category #2" }); - const loadedPost3 = await connection.manager.findOneById(Post, 3); + const loadedPost3 = await connection.manager.findOne(Post, 3); const loadedCategory3: Category = await connection .createQueryBuilder() .relation(Post, "category") diff --git a/test/functional/query-builder/relational/with-one/query-builder-relational-set-many-to-one.ts b/test/functional/query-builder/relational/with-one/query-builder-relational-set-many-to-one.ts index a0656498af..abb8e83767 100644 --- a/test/functional/query-builder/relational/with-one/query-builder-relational-set-many-to-one.ts +++ b/test/functional/query-builder/relational/with-one/query-builder-relational-set-many-to-one.ts @@ -47,13 +47,13 @@ describe("query builder > relational query builder > set operation > many to one .of(post1) .set(category1); - let loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["category"] }); + let loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["category"] }); expect(loadedPost1!.category).to.be.eql({ id: 1, name: "category #1" }); - let loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["category"] }); + let loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["category"] }); expect(loadedPost2!.category).to.be.undefined; - let loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["category"] }); + let loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["category"] }); expect(loadedPost3!.category).to.be.undefined; await connection @@ -62,13 +62,13 @@ describe("query builder > relational query builder > set operation > many to one .of(post1) .set(null); - loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["category"] }); + loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["category"] }); expect(loadedPost1!.category).to.be.undefined; - loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["category"] }); + loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["category"] }); expect(loadedPost2!.category).to.be.undefined; - loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["category"] }); + loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["category"] }); expect(loadedPost3!.category).to.be.undefined; }))); @@ -104,13 +104,13 @@ describe("query builder > relational query builder > set operation > many to one .of(2) .set(2); - let loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["category"] }); + let loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["category"] }); expect(loadedPost1!.category).to.be.undefined; - let loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["category"] }); + let loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["category"] }); expect(loadedPost2!.category).to.be.eql({ id: 2, name: "category #2" }); - let loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["category"] }); + let loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["category"] }); expect(loadedPost3!.category).to.be.undefined; await connection @@ -119,13 +119,13 @@ describe("query builder > relational query builder > set operation > many to one .of(2) .set(null); - loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["category"] }); + loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["category"] }); expect(loadedPost1!.category).to.be.undefined; - loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["category"] }); + loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["category"] }); expect(loadedPost2!.category).to.be.undefined; - loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["category"] }); + loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["category"] }); expect(loadedPost3!.category).to.be.undefined; }))); @@ -161,13 +161,13 @@ describe("query builder > relational query builder > set operation > many to one .of({ id: 3 }) .set({ id: 3 }); - let loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["category"] }); + let loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["category"] }); expect(loadedPost1!.category).to.be.undefined; - let loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["category"] }); + let loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["category"] }); expect(loadedPost2!.category).to.be.undefined; - let loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["category"] }); + let loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["category"] }); expect(loadedPost3!.category).to.be.eql({ id: 3, name: "category #3" }); await connection @@ -176,13 +176,13 @@ describe("query builder > relational query builder > set operation > many to one .of({ id: 3 }) .set(null); - loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["category"] }); + loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["category"] }); expect(loadedPost1!.category).to.be.undefined; - loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["category"] }); + loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["category"] }); expect(loadedPost2!.category).to.be.undefined; - loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["category"] }); + loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["category"] }); expect(loadedPost3!.category).to.be.undefined; }))); @@ -218,13 +218,13 @@ describe("query builder > relational query builder > set operation > many to one .of([{ id: 1 }, { id: 3 }]) .set({ id: 3 }); - let loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["category"] }); + let loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["category"] }); expect(loadedPost1!.category).to.be.eql({ id: 3, name: "category #3" }); - let loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["category"] }); + let loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["category"] }); expect(loadedPost2!.category).to.be.undefined; - let loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["category"] }); + let loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["category"] }); expect(loadedPost3!.category).to.be.eql({ id: 3, name: "category #3" }); await connection @@ -233,13 +233,13 @@ describe("query builder > relational query builder > set operation > many to one .of([{ id: 1 }, { id: 3 }]) .set(null); - loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["category"] }); + loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["category"] }); expect(loadedPost1!.category).to.be.undefined; - loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["category"] }); + loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["category"] }); expect(loadedPost2!.category).to.be.undefined; - loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["category"] }); + loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["category"] }); expect(loadedPost3!.category).to.be.undefined; }))); diff --git a/test/functional/query-builder/relational/with-one/query-builder-relational-set-one-to-one-inverse.ts b/test/functional/query-builder/relational/with-one/query-builder-relational-set-one-to-one-inverse.ts index 1f3b6667d1..10d0341956 100644 --- a/test/functional/query-builder/relational/with-one/query-builder-relational-set-one-to-one-inverse.ts +++ b/test/functional/query-builder/relational/with-one/query-builder-relational-set-one-to-one-inverse.ts @@ -47,13 +47,13 @@ describe("query builder > relational query builder > set operation > one-to-one .of(image1) .set(post1); - let loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["image"] }); + let loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["image"] }); expect(loadedPost1!.image).to.be.eql({ id: 1, url: "image #1" }); - let loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["image"] }); + let loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["image"] }); expect(loadedPost2!.image).to.be.undefined; - let loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["image"] }); + let loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["image"] }); expect(loadedPost3!.image).to.be.undefined; await connection @@ -62,13 +62,13 @@ describe("query builder > relational query builder > set operation > one-to-one .of(image1) .set(null); - loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["image"] }); + loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["image"] }); expect(loadedPost1!.image).to.be.undefined; - loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["image"] }); + loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["image"] }); expect(loadedPost2!.image).to.be.undefined; - loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["image"] }); + loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["image"] }); expect(loadedPost3!.image).to.be.undefined; }))); @@ -104,13 +104,13 @@ describe("query builder > relational query builder > set operation > one-to-one .of(2) .set(2); - let loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["image"] }); + let loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["image"] }); expect(loadedPost1!.image).to.be.undefined; - let loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["image"] }); + let loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["image"] }); expect(loadedPost2!.image).to.be.eql({ id: 2, url: "image #2" }); - let loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["image"] }); + let loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["image"] }); expect(loadedPost3!.image).to.be.undefined; await connection @@ -119,13 +119,13 @@ describe("query builder > relational query builder > set operation > one-to-one .of(2) .set(null); - loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["image"] }); + loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["image"] }); expect(loadedPost1!.image).to.be.undefined; - loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["image"] }); + loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["image"] }); expect(loadedPost2!.image).to.be.undefined; - loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["image"] }); + loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["image"] }); expect(loadedPost3!.image).to.be.undefined; }))); @@ -161,13 +161,13 @@ describe("query builder > relational query builder > set operation > one-to-one .of({ id: 3 }) .set({ id: 3 }); - let loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["image"] }); + let loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["image"] }); expect(loadedPost1!.image).to.be.undefined; - let loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["image"] }); + let loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["image"] }); expect(loadedPost2!.image).to.be.undefined; - let loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["image"] }); + let loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["image"] }); expect(loadedPost3!.image).to.be.eql({ id: 3, url: "image #3" }); await connection @@ -176,13 +176,13 @@ describe("query builder > relational query builder > set operation > one-to-one .of({ id: 3 }) .set(null); - loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["image"] }); + loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["image"] }); expect(loadedPost1!.image).to.be.undefined; - loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["image"] }); + loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["image"] }); expect(loadedPost2!.image).to.be.undefined; - loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["image"] }); + loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["image"] }); expect(loadedPost3!.image).to.be.undefined; }))); @@ -218,13 +218,13 @@ describe("query builder > relational query builder > set operation > one-to-one .of({ id: 3 }) .set([{ id: 1 }, { id: 3 }]); - let loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["image"] }); + let loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["image"] }); expect(loadedPost1!.image).to.be.eql({ id: 3, url: "image #3" }); - let loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["image"] }); + let loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["image"] }); expect(loadedPost2!.image).to.be.undefined; - let loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["image"] }); + let loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["image"] }); expect(loadedPost3!.image).to.be.eql({ id: 3, url: "image #3" }); await connection @@ -233,13 +233,13 @@ describe("query builder > relational query builder > set operation > one-to-one .of({ id: 3 }) .set(null); - loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["image"] }); + loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["image"] }); expect(loadedPost1!.image).to.be.undefined; - loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["image"] }); + loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["image"] }); expect(loadedPost2!.image).to.be.undefined; - loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["image"] }); + loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["image"] }); expect(loadedPost3!.image).to.be.undefined; }))); diff --git a/test/functional/query-builder/relational/with-one/query-builder-relational-set-one-to-one.ts b/test/functional/query-builder/relational/with-one/query-builder-relational-set-one-to-one.ts index 3d2d2d3c9e..b8188e53ad 100644 --- a/test/functional/query-builder/relational/with-one/query-builder-relational-set-one-to-one.ts +++ b/test/functional/query-builder/relational/with-one/query-builder-relational-set-one-to-one.ts @@ -47,13 +47,13 @@ describe("query builder > relational query builder > set operation > one-to-one .of(post1) .set(image1); - let loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["image"] }); + let loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["image"] }); expect(loadedPost1!.image).to.be.eql({ id: 1, url: "image #1" }); - let loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["image"] }); + let loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["image"] }); expect(loadedPost2!.image).to.be.undefined; - let loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["image"] }); + let loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["image"] }); expect(loadedPost3!.image).to.be.undefined; await connection @@ -62,13 +62,13 @@ describe("query builder > relational query builder > set operation > one-to-one .of(post1) .set(null); - loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["image"] }); + loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["image"] }); expect(loadedPost1!.image).to.be.undefined; - loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["image"] }); + loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["image"] }); expect(loadedPost2!.image).to.be.undefined; - loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["image"] }); + loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["image"] }); expect(loadedPost3!.image).to.be.undefined; }))); @@ -104,13 +104,13 @@ describe("query builder > relational query builder > set operation > one-to-one .of(2) .set(2); - let loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["image"] }); + let loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["image"] }); expect(loadedPost1!.image).to.be.undefined; - let loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["image"] }); + let loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["image"] }); expect(loadedPost2!.image).to.be.eql({ id: 2, url: "image #2" }); - let loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["image"] }); + let loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["image"] }); expect(loadedPost3!.image).to.be.undefined; await connection @@ -119,13 +119,13 @@ describe("query builder > relational query builder > set operation > one-to-one .of(2) .set(null); - loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["image"] }); + loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["image"] }); expect(loadedPost1!.image).to.be.undefined; - loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["image"] }); + loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["image"] }); expect(loadedPost2!.image).to.be.undefined; - loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["image"] }); + loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["image"] }); expect(loadedPost3!.image).to.be.undefined; }))); @@ -161,13 +161,13 @@ describe("query builder > relational query builder > set operation > one-to-one .of({ id: 3 }) .set({ id: 3 }); - let loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["image"] }); + let loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["image"] }); expect(loadedPost1!.image).to.be.undefined; - let loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["image"] }); + let loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["image"] }); expect(loadedPost2!.image).to.be.undefined; - let loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["image"] }); + let loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["image"] }); expect(loadedPost3!.image).to.be.eql({ id: 3, url: "image #3" }); await connection @@ -176,13 +176,13 @@ describe("query builder > relational query builder > set operation > one-to-one .of({ id: 3 }) .set(null); - loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["image"] }); + loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["image"] }); expect(loadedPost1!.image).to.be.undefined; - loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["image"] }); + loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["image"] }); expect(loadedPost2!.image).to.be.undefined; - loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["image"] }); + loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["image"] }); expect(loadedPost3!.image).to.be.undefined; }))); @@ -218,13 +218,13 @@ describe("query builder > relational query builder > set operation > one-to-one .of([{ id: 1 }, { id: 3 }]) .set({ id: 3 }); - let loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["image"] }); + let loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["image"] }); expect(loadedPost1!.image).to.be.eql({ id: 3, url: "image #3" }); - let loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["image"] }); + let loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["image"] }); expect(loadedPost2!.image).to.be.undefined; - let loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["image"] }); + let loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["image"] }); expect(loadedPost3!.image).to.be.eql({ id: 3, url: "image #3" }); await connection @@ -233,13 +233,13 @@ describe("query builder > relational query builder > set operation > one-to-one .of([{ id: 1 }, { id: 3 }]) .set(null); - loadedPost1 = await connection.manager.findOneById(Post, 1, { relations: ["image"] }); + loadedPost1 = await connection.manager.findOne(Post, 1, { relations: ["image"] }); expect(loadedPost1!.image).to.be.undefined; - loadedPost2 = await connection.manager.findOneById(Post, 2, { relations: ["image"] }); + loadedPost2 = await connection.manager.findOne(Post, 2, { relations: ["image"] }); expect(loadedPost2!.image).to.be.undefined; - loadedPost3 = await connection.manager.findOneById(Post, 3, { relations: ["image"] }); + loadedPost3 = await connection.manager.findOne(Post, 3, { relations: ["image"] }); expect(loadedPost3!.image).to.be.undefined; }))); diff --git a/test/functional/relations/eager-relations/basic-eager-relations/basic-eager-relations.ts b/test/functional/relations/eager-relations/basic-eager-relations/basic-eager-relations.ts index 0693bb341e..fd491375db 100644 --- a/test/functional/relations/eager-relations/basic-eager-relations/basic-eager-relations.ts +++ b/test/functional/relations/eager-relations/basic-eager-relations/basic-eager-relations.ts @@ -60,7 +60,7 @@ describe("relations > eager relations > basic", () => { it("should load all eager relations when object is loaded", () => Promise.all(connections.map(async connection => { await prepareData(connection); - const loadedPost = await connection.manager.findOneById(Post, 1); + const loadedPost = await connection.manager.findOne(Post, 1); loadedPost!.should.be.eql({ id: 1, title: "about eager relations", diff --git a/test/functional/relations/lazy-relations/basic-lazy-relation/basic-lazy-relations.ts b/test/functional/relations/lazy-relations/basic-lazy-relation/basic-lazy-relations.ts index 8559396afc..ff06ccd641 100644 --- a/test/functional/relations/lazy-relations/basic-lazy-relation/basic-lazy-relations.ts +++ b/test/functional/relations/lazy-relations/basic-lazy-relation/basic-lazy-relations.ts @@ -60,7 +60,7 @@ describe("basic-lazy-relations", () => { savedPost.categories.should.eventually.be.eql([savedCategory1, savedCategory2, savedCategory3]); - const post = (await postRepository.findOneById(1))!; + const post = (await postRepository.findOne(1))!; post.title.should.be.equal("Hello post"); post.text.should.be.equal("This is post about post"); @@ -100,7 +100,7 @@ describe("basic-lazy-relations", () => { savedPost.twoSideCategories.should.eventually.be.eql([savedCategory1, savedCategory2, savedCategory3]); - const post = (await postRepository.findOneById(1))!; + const post = (await postRepository.findOne(1))!; post.title.should.be.equal("Hello post"); post.text.should.be.equal("This is post about post"); @@ -112,7 +112,7 @@ describe("basic-lazy-relations", () => { categories.should.contain(savedCategory2); categories.should.contain(savedCategory3); - const category = (await categoryRepository.findOneById(1))!; + const category = (await categoryRepository.findOne(1))!; category.name.should.be.equal("kids"); const twoSidePosts = await category.twoSidePosts; @@ -141,7 +141,7 @@ describe("basic-lazy-relations", () => { newUser.profile.should.eventually.be.eql(profile); // const loadOptions: FindOptions = { alias: "user", innerJoinAndSelect }; - const loadedUser: any = await userRepository.findOneById(1); + const loadedUser: any = await userRepository.findOne(1); loadedUser.firstName.should.be.equal("Umed"); loadedUser.secondName.should.be.equal("San"); loadedUser.profile.should.be.instanceOf(Promise); diff --git a/test/functional/relations/lazy-relations/named-columns/named-columns-lazy-relations.ts b/test/functional/relations/lazy-relations/named-columns/named-columns-lazy-relations.ts index 95011dfc57..7a23cac662 100644 --- a/test/functional/relations/lazy-relations/named-columns/named-columns-lazy-relations.ts +++ b/test/functional/relations/lazy-relations/named-columns/named-columns-lazy-relations.ts @@ -53,7 +53,7 @@ describe("named-columns-lazy-relations", () => { savedPost.categories.should.eventually.be.eql([savedCategory1, savedCategory2, savedCategory3]); - const post = (await postRepository.findOneById(1))!; + const post = (await postRepository.findOne(1))!; post.title.should.be.equal("Hello post"); post.text.should.be.equal("This is post about post"); @@ -93,7 +93,7 @@ describe("named-columns-lazy-relations", () => { savedPost.twoSideCategories.should.eventually.be.eql([savedCategory1, savedCategory2, savedCategory3]); - const post = (await postRepository.findOneById(1))!; + const post = (await postRepository.findOne(1))!; post.title.should.be.equal("Hello post"); post.text.should.be.equal("This is post about post"); @@ -105,7 +105,7 @@ describe("named-columns-lazy-relations", () => { categories.should.contain(savedCategory2); categories.should.contain(savedCategory3); - const category = (await categoryRepository.findOneById(1))!; + const category = (await categoryRepository.findOne(1))!; category.name.should.be.equal("kids"); const twoSidePosts = await category.twoSidePosts; diff --git a/test/functional/relations/lazy-relations/named-tables-and-columns/named-tables-and-columns-lazy-relations.ts b/test/functional/relations/lazy-relations/named-tables-and-columns/named-tables-and-columns-lazy-relations.ts index 214110bf8c..e2a3a1443f 100644 --- a/test/functional/relations/lazy-relations/named-tables-and-columns/named-tables-and-columns-lazy-relations.ts +++ b/test/functional/relations/lazy-relations/named-tables-and-columns/named-tables-and-columns-lazy-relations.ts @@ -53,7 +53,7 @@ describe("named-tables-and-columns-lazy-relations", () => { savedPost.categories.should.eventually.be.eql([savedCategory1, savedCategory2, savedCategory3]); - const post = (await postRepository.findOneById(1))!; + const post = (await postRepository.findOne(1))!; post.title.should.be.equal("Hello post"); post.text.should.be.equal("This is post about post"); @@ -93,7 +93,7 @@ describe("named-tables-and-columns-lazy-relations", () => { savedPost.twoSideCategories.should.eventually.be.eql([savedCategory1, savedCategory2, savedCategory3]); - const post = (await postRepository.findOneById(1))!; + const post = (await postRepository.findOne(1))!; post.title.should.be.equal("Hello post"); post.text.should.be.equal("This is post about post"); @@ -105,7 +105,7 @@ describe("named-tables-and-columns-lazy-relations", () => { categories.should.contain(savedCategory2); categories.should.contain(savedCategory3); - const category = (await categoryRepository.findOneById(1))!; + const category = (await categoryRepository.findOne(1))!; category.name.should.be.equal("kids"); const twoSidePosts = await category.twoSidePosts; diff --git a/test/functional/relations/lazy-relations/named-tables/named-tables-lazy-relations.ts b/test/functional/relations/lazy-relations/named-tables/named-tables-lazy-relations.ts index aab6469395..2f636ea06b 100644 --- a/test/functional/relations/lazy-relations/named-tables/named-tables-lazy-relations.ts +++ b/test/functional/relations/lazy-relations/named-tables/named-tables-lazy-relations.ts @@ -53,7 +53,7 @@ describe("named-tables-lazy-relations", () => { savedPost.categories.should.eventually.be.eql([savedCategory1, savedCategory2, savedCategory3]); - const post = (await postRepository.findOneById(1))!; + const post = (await postRepository.findOne(1))!; post.title.should.be.equal("Hello post"); post.text.should.be.equal("This is post about post"); @@ -93,7 +93,7 @@ describe("named-tables-lazy-relations", () => { savedPost.twoSideCategories.should.eventually.be.eql([savedCategory1, savedCategory2, savedCategory3]); - const post = (await postRepository.findOneById(1))!; + const post = (await postRepository.findOne(1))!; post.title.should.be.equal("Hello post"); post.text.should.be.equal("This is post about post"); @@ -105,7 +105,7 @@ describe("named-tables-lazy-relations", () => { categories.should.contain(savedCategory2); categories.should.contain(savedCategory3); - const category = (await categoryRepository.findOneById(1))!; + const category = (await categoryRepository.findOne(1))!; category.name.should.be.equal("kids"); const twoSidePosts = await category.twoSidePosts; diff --git a/test/functional/repository/find-methods/repostiory-find-methods.ts b/test/functional/repository/find-methods/repostiory-find-methods.ts index 4bcd31c199..b5c08370f9 100644 --- a/test/functional/repository/find-methods/repostiory-find-methods.ts +++ b/test/functional/repository/find-methods/repostiory-find-methods.ts @@ -436,7 +436,7 @@ describe("repository > find methods", () => { }); - describe("findOneById", function() { + describe("findOne", function() { it("should return entity by a given id", () => Promise.all(connections.map(async connection => { const userRepository = connection.getRepository("User"); @@ -453,17 +453,17 @@ describe("repository > find methods", () => { const savedUsers = await Promise.all(promises); savedUsers.length.should.be.equal(100); // check if they all are saved - let loadedUser = (await userRepository.findOneById(0))!; + let loadedUser = (await userRepository.findOne(0))!; loadedUser.id.should.be.equal(0); loadedUser.firstName.should.be.equal("name #0"); loadedUser.secondName.should.be.equal("Doe"); - loadedUser = (await userRepository.findOneById(1))!; + loadedUser = (await userRepository.findOne(1))!; loadedUser.id.should.be.equal(1); loadedUser.firstName.should.be.equal("name #1"); loadedUser.secondName.should.be.equal("Doe"); - loadedUser = (await userRepository.findOneById(99))!; + loadedUser = (await userRepository.findOne(99))!; loadedUser.id.should.be.equal(99); loadedUser.firstName.should.be.equal("name #99"); loadedUser.secondName.should.be.equal("Doe"); @@ -484,7 +484,7 @@ describe("repository > find methods", () => { const savedUsers = await Promise.all(promises); savedUsers.length.should.be.equal(100); // check if they all are saved - let loadedUser = await userRepository.findOneById(0, { + let loadedUser = await userRepository.findOne(0, { where: { secondName: "Doe" } @@ -493,7 +493,7 @@ describe("repository > find methods", () => { loadedUser!.firstName.should.be.equal("name #0"); loadedUser!.secondName.should.be.equal("Doe"); - loadedUser = await userRepository.findOneById(1, { + loadedUser = await userRepository.findOne(1, { where: { secondName: "Dorian" } diff --git a/test/functional/repository/set-add-remove-relations/repository-set-add-remove-relations.ts b/test/functional/repository/set-add-remove-relations/repository-set-add-remove-relations.ts index ee916f8afd..409f961c15 100644 --- a/test/functional/repository/set-add-remove-relations/repository-set-add-remove-relations.ts +++ b/test/functional/repository/set-add-remove-relations/repository-set-add-remove-relations.ts @@ -49,7 +49,7 @@ describe.skip("repository > set/add/remove relation methods", function() { // await postSpecificRepository.addToRelation(post => post.manyCategories, newPost.id, [newCategory1.id, newCategory2.id]); // load a post, want to have categories count - const loadedPost = await postRepository.findOneById(1, { + const loadedPost = await postRepository.findOne(1, { join: { alias: "post", leftJoinAndSelect: { @@ -89,7 +89,7 @@ describe.skip("repository > set/add/remove relation methods", function() { // await categorySpecificRepository.addToRelation(category => category.manyPosts, newCategory.id, [newPost1.id, newPost2.id]); // load a post, want to have categories count - const loadedCategory = await categoryRepository.findOneById(1, { + const loadedCategory = await categoryRepository.findOne(1, { join: { alias: "category", leftJoinAndSelect: { manyPosts: "category.manyPosts" } } @@ -132,7 +132,7 @@ describe.skip("repository > set/add/remove relation methods", function() { // await postSpecificRepository.removeFromRelation(post => post.manyCategories, newPost.id, [newCategory1.id, newCategory3.id]); // load a post, want to have categories count - const loadedPost = await postRepository.findOneById(1, { + const loadedPost = await postRepository.findOne(1, { join: { alias: "post", leftJoinAndSelect: { manyCategories: "post.manyCategories" } @@ -176,7 +176,7 @@ describe.skip("repository > set/add/remove relation methods", function() { // await categorySpecificRepository.removeFromRelation(post => post.manyPosts, newCategory.id, [newPost1.id, newPost3.id]); // load a post, want to have categories count - const loadedCategory = await categoryRepository.findOneById(1, { + const loadedCategory = await categoryRepository.findOne(1, { join: { alias: "category", leftJoinAndSelect: { manyPosts: "category.manyPosts" } @@ -209,7 +209,7 @@ describe.skip("repository > set/add/remove relation methods", function() { // await postSpecificRepository.setRelation(post => post.categories, newPost.id, newCategory1.id); // load a post, want to have categories count - const loadedPost = await postRepository.findOneById(1, { + const loadedPost = await postRepository.findOne(1, { join: { alias: "post", leftJoinAndSelect: { categories: "post.categories" } @@ -241,7 +241,7 @@ describe.skip("repository > set/add/remove relation methods", function() { // await categorySpecificRepository.setRelation(category => category.post, newCategory.id, newPost.id); // load a post, want to have categories count - const loadedCategory = await categoryRepository.findOneById(1, { + const loadedCategory = await categoryRepository.findOne(1, { join: { alias: "category", leftJoinAndSelect: { post: "category.post" } @@ -272,7 +272,7 @@ describe.skip("repository > set/add/remove relation methods", function() { // await postSpecificRepository.setRelation(post => post.categories, newPost.id, null); // load a post, want to have categories count - const loadedPost = await postRepository.findOneById(1, { + const loadedPost = await postRepository.findOne(1, { join: { alias: "post", leftJoinAndSelect: { categories: "post.categories" } @@ -303,7 +303,7 @@ describe.skip("repository > set/add/remove relation methods", function() { // await categorySpecificRepository.setRelation(category => category.post, newCategory.id, null); // load a post, want to have categories count - const loadedCategory = await categoryRepository.findOneById(1, { + const loadedCategory = await categoryRepository.findOne(1, { join: { alias: "category", leftJoinAndSelect: { post: "category.post" } diff --git a/test/functional/uuid/mssql/uuid-mssql.ts b/test/functional/uuid/mssql/uuid-mssql.ts index 046d150c03..0ac29e7e16 100644 --- a/test/functional/uuid/mssql/uuid-mssql.ts +++ b/test/functional/uuid/mssql/uuid-mssql.ts @@ -30,19 +30,19 @@ describe("uuid-mssql", () => { const post = new Post(); await postRepository.save(post); - const loadedPost = await postRepository.findOneById(1); + const loadedPost = await postRepository.findOne(1); expect(loadedPost!.uuid).to.be.exist; postTableSchema!.findColumnByName("uuid")!.type.should.be.equal("uniqueidentifier"); const post2 = new Post(); post2.uuid = "FD357B8F-8838-42F6-B7A2-AE027444E895"; await postRepository.save(post2); - const loadedPost2 = await postRepository.findOneById(2); + const loadedPost2 = await postRepository.findOne(2); expect(loadedPost2!.uuid).to.equal("FD357B8F-8838-42F6-B7A2-AE027444E895"); const question = new Question(); const savedQuestion = await questionRepository.save(question); - const loadedQuestion = await questionRepository.findOneById(savedQuestion.id); + const loadedQuestion = await questionRepository.findOne(savedQuestion.id); expect(loadedQuestion!.id).to.be.exist; expect(loadedQuestion!.uuid).to.be.exist; expect(loadedQuestion!.uuid2).to.be.null; @@ -58,7 +58,7 @@ describe("uuid-mssql", () => { question2.uuid2 = null; question2.uuid3 = null; await questionRepository.save(question2); - const loadedQuestion2 = await questionRepository.findOneById("1ECAD7F6-23EE-453E-BB44-16ECA26D5189"); + const loadedQuestion2 = await questionRepository.findOne("1ECAD7F6-23EE-453E-BB44-16ECA26D5189"); expect(loadedQuestion2!.id).to.equal("1ECAD7F6-23EE-453E-BB44-16ECA26D5189"); expect(loadedQuestion2!.uuid).to.equal("35B44650-B2CD-44EC-AA54-137FBDF1C373"); expect(loadedQuestion2!.uuid2).to.be.null; diff --git a/test/functional/uuid/mysql/uuid-mysql.ts b/test/functional/uuid/mysql/uuid-mysql.ts index 51b85582b0..49bccdc4fd 100644 --- a/test/functional/uuid/mysql/uuid-mysql.ts +++ b/test/functional/uuid/mysql/uuid-mysql.ts @@ -5,7 +5,7 @@ import {closeTestingConnections, createTestingConnections, reloadTestingDatabase import {Post} from "./entity/Post"; import {Question} from "./entity/Question"; -describe.only("uuid-mysql", () => { +describe("uuid-mysql", () => { let connections: Connection[]; before(async () => { diff --git a/test/functional/uuid/postgres/uuid-postgres.ts b/test/functional/uuid/postgres/uuid-postgres.ts index 9f96b2835e..9e22a3fd51 100644 --- a/test/functional/uuid/postgres/uuid-postgres.ts +++ b/test/functional/uuid/postgres/uuid-postgres.ts @@ -32,7 +32,7 @@ describe("uuid-postgres", () => { const record = new Record(); record.id = "fd357b8f-8838-42f6-b7a2-ae027444e895"; const persistedRecord = await recordRepo.save(record); - const foundRecord = await recordRepo.findOneById(persistedRecord.id); + const foundRecord = await recordRepo.findOne(persistedRecord.id); expect(foundRecord).to.be.exist; expect(foundRecord!.id).to.eq("fd357b8f-8838-42f6-b7a2-ae027444e895"); }))); @@ -48,14 +48,14 @@ describe("uuid-postgres", () => { const post = new Post(); await postRepository.save(post); - const loadedPost = await postRepository.findOneById(1); + const loadedPost = await postRepository.findOne(1); expect(loadedPost!.uuid).to.be.exist; postTableSchema!.findColumnByName("uuid")!.type.should.be.equal("uuid"); const post2 = new Post(); post2.uuid = "fd357b8f-8838-42f6-b7a2-ae027444e895"; await postRepository.save(post2); - const loadedPost2 = await postRepository.findOneById(2); + const loadedPost2 = await postRepository.findOne(2); expect(loadedPost2!.uuid).to.equal("fd357b8f-8838-42f6-b7a2-ae027444e895"); const question = new Question(); @@ -68,7 +68,7 @@ describe("uuid-postgres", () => { expect(savedQuestion!.uuid3).to.be.null; expect(savedQuestion!.uuid4).to.be.exist; - const loadedQuestion = await questionRepository.findOneById(savedQuestion.id); + const loadedQuestion = await questionRepository.findOne(savedQuestion.id); expect(loadedQuestion!.id).to.be.exist; expect(loadedQuestion!.uuid).to.be.exist; expect(loadedQuestion!.uuid2).to.equal("fd357b8f-8838-42f6-b7a2-ae027444e895"); @@ -86,7 +86,7 @@ describe("uuid-postgres", () => { question2.uuid3 = null; question2.uuid4 = null; await questionRepository.save(question2); - const loadedQuestion2 = await questionRepository.findOneById("1ecad7f6-23ee-453e-bb44-16eca26d5189"); + const loadedQuestion2 = await questionRepository.findOne("1ecad7f6-23ee-453e-bb44-16eca26d5189"); expect(loadedQuestion2!.id).to.equal("1ecad7f6-23ee-453e-bb44-16eca26d5189"); expect(loadedQuestion2!.uuid).to.equal("35b44650-b2cd-44ec-aa54-137fbdf1c373"); expect(loadedQuestion2!.uuid2).to.equal("fd357b8f-8838-42f6-b7a2-ae027444e895"); diff --git a/test/functional/uuid/sqlite/uuid-sqlite.ts b/test/functional/uuid/sqlite/uuid-sqlite.ts index ba9fa6baaa..03a1d668e6 100644 --- a/test/functional/uuid/sqlite/uuid-sqlite.ts +++ b/test/functional/uuid/sqlite/uuid-sqlite.ts @@ -30,20 +30,20 @@ describe("uuid-sqlite", () => { const post = new Post(); await postRepository.save(post); - const loadedPost = await postRepository.findOneById(1); + const loadedPost = await postRepository.findOne(1); expect(loadedPost!.uuid).to.be.exist; postTableSchema!.findColumnByName("uuid")!.type.should.be.equal("varchar"); const post2 = new Post(); post2.uuid = "fd357b8f-8838-42f6-b7a2-ae027444e895"; await postRepository.save(post2); - const loadedPost2 = await postRepository.findOneById(2); + const loadedPost2 = await postRepository.findOne(2); expect(loadedPost2!.uuid).to.equal("fd357b8f-8838-42f6-b7a2-ae027444e895"); const question = new Question(); question.uuid2 = "fd357b8f-8838-42f6-b7a2-ae027444e895"; const savedQuestion = await questionRepository.save(question); - const loadedQuestion = await questionRepository.findOneById(savedQuestion.id); + const loadedQuestion = await questionRepository.findOne(savedQuestion.id); expect(loadedQuestion!.id).to.be.exist; expect(loadedQuestion!.uuid).to.be.exist; expect(loadedQuestion!.uuid2).to.equal("fd357b8f-8838-42f6-b7a2-ae027444e895"); @@ -61,7 +61,7 @@ describe("uuid-sqlite", () => { question2.uuid3 = null; question2.uuid4 = null; await questionRepository.save(question2); - const loadedQuestion2 = await questionRepository.findOneById("1ecad7f6-23ee-453e-bb44-16eca26d5189"); + const loadedQuestion2 = await questionRepository.findOne("1ecad7f6-23ee-453e-bb44-16eca26d5189"); expect(loadedQuestion2!.id).to.equal("1ecad7f6-23ee-453e-bb44-16eca26d5189"); expect(loadedQuestion2!.uuid).to.equal("35b44650-b2cd-44ec-aa54-137fbdf1c373"); expect(loadedQuestion2!.uuid2).to.equal("fd357b8f-8838-42f6-b7a2-ae027444e895"); diff --git a/test/github-issues/1014/issue-1014.ts b/test/github-issues/1014/issue-1014.ts index 739bfd0517..ffab6de558 100644 --- a/test/github-issues/1014/issue-1014.ts +++ b/test/github-issues/1014/issue-1014.ts @@ -32,7 +32,7 @@ describe("github issues > #1014 Transaction doesn't rollback", () => { } catch (err) { error = err; } expect(error).to.be.instanceof(Error); - const loadedTestEntity = await connection.manager.findOneById(TestEntity, 1); + const loadedTestEntity = await connection.manager.findOne(TestEntity, 1); expect(loadedTestEntity).not.to.be.empty; loadedTestEntity!.should.be.eql({ id: 1, name: "Hello Test" }); }))); diff --git a/test/github-issues/1042/issue-1042.ts b/test/github-issues/1042/issue-1042.ts index 379c5b53d0..e626e394a0 100644 --- a/test/github-issues/1042/issue-1042.ts +++ b/test/github-issues/1042/issue-1042.ts @@ -33,7 +33,7 @@ describe("github issues > #1042 EntityMetadataUtils.createPropertyPath does not await connection.manager.save(user); // load and check if saved user is correct - const loadedUser = await connection.manager.findOneById(User, 1); + const loadedUser = await connection.manager.findOne(User, 1); expect(loadedUser).not.to.be.empty; loadedUser!.should.be.eql({ id: 1, @@ -66,7 +66,7 @@ describe("github issues > #1042 EntityMetadataUtils.createPropertyPath does not .execute(); // load and check again - const loadedUser2 = await connection.manager.findOneById(User, 1); + const loadedUser2 = await connection.manager.findOne(User, 1); expect(loadedUser2).not.to.be.empty; loadedUser2!.should.be.eql({ id: 1, @@ -100,7 +100,7 @@ describe("github issues > #1042 EntityMetadataUtils.createPropertyPath does not .execute(); // load and check again - const loadedUser3 = await connection.manager.findOneById(User, 1); + const loadedUser3 = await connection.manager.findOne(User, 1); expect(loadedUser3).not.to.be.empty; loadedUser3!.should.be.eql({ id: 1, @@ -134,7 +134,7 @@ describe("github issues > #1042 EntityMetadataUtils.createPropertyPath does not .execute(); // load and check again - const loadedUser4 = await connection.manager.findOneById(User, 1); + const loadedUser4 = await connection.manager.findOne(User, 1); expect(loadedUser4).not.to.be.empty; loadedUser4!.should.be.eql({ id: 1, diff --git a/test/github-issues/151/issue-151.ts b/test/github-issues/151/issue-151.ts index 0fa52114fa..dd5e992a63 100644 --- a/test/github-issues/151/issue-151.ts +++ b/test/github-issues/151/issue-151.ts @@ -27,7 +27,7 @@ describe("github issues > #151 joinAndSelect can't find entity from inverse side await connection.manager.save(post); - const loadedPost = await connection.manager.findOneById(Post, 1, { + const loadedPost = await connection.manager.findOne(Post, 1, { join: { alias: "post", innerJoinAndSelect: { diff --git a/test/github-issues/161/issue-161.ts b/test/github-issues/161/issue-161.ts index 1928ac45d6..1d1b23b63a 100644 --- a/test/github-issues/161/issue-161.ts +++ b/test/github-issues/161/issue-161.ts @@ -29,7 +29,7 @@ describe("github issues > #161 joinAndSelect can't find entity from inverse side await connection.manager.save(ticket); - const loadedTicketWithRequest = await connection.manager.findOneById(Ticket, 1, { + const loadedTicketWithRequest = await connection.manager.findOne(Ticket, 1, { join: { alias: "ticket", innerJoinAndSelect: { @@ -50,7 +50,7 @@ describe("github issues > #161 joinAndSelect can't find entity from inverse side } }); - const loadedRequestWithTicket = await connection.manager.findOneById(Request, 1, { + const loadedRequestWithTicket = await connection.manager.findOne(Request, 1, { join: { alias: "request", innerJoinAndSelect: { @@ -94,7 +94,7 @@ describe("github issues > #161 joinAndSelect can't find entity from inverse side await connection.manager.save(request); - const loadedRequest = await connection.manager.findOneById(Request, 2, { + const loadedRequest = await connection.manager.findOne(Request, 2, { join: { alias: "request", innerJoinAndSelect: { ticket: "request.ticket" } diff --git a/test/github-issues/204/issue-204.ts b/test/github-issues/204/issue-204.ts index 284f589b2f..ac17926e0b 100644 --- a/test/github-issues/204/issue-204.ts +++ b/test/github-issues/204/issue-204.ts @@ -29,7 +29,7 @@ describe("github issues > #204 jsonb array is not persisted correctly", () => { ]; await connection.manager.save(record); - const foundRecord = await connection.manager.findOneById(Record, record.id); + const foundRecord = await connection.manager.findOne(Record, record.id); expect(foundRecord).to.be.not.undefined; foundRecord!.datas.should.be.eql([ new RecordData("hello1", "hello2", "hello3", "hello4", true, false), diff --git a/test/github-issues/433/issue-433.ts b/test/github-issues/433/issue-433.ts index 8947adcc8c..b68960d8c7 100644 --- a/test/github-issues/433/issue-433.ts +++ b/test/github-issues/433/issue-433.ts @@ -19,7 +19,7 @@ describe("github issues > #433 default value (json) is not getting set in postgr const post = new Post(); post.id = 1; await connection.getRepository(Post).save(post); - const loadedPost = (await connection.getRepository(Post).findOneById(1))!; + const loadedPost = (await connection.getRepository(Post).findOne(1))!; loadedPost.json.should.be.eql({ hello: "world" }); }))); diff --git a/test/github-issues/463/issue-463.ts b/test/github-issues/463/issue-463.ts index c157a2d458..6f1f45b298 100644 --- a/test/github-issues/463/issue-463.ts +++ b/test/github-issues/463/issue-463.ts @@ -19,7 +19,7 @@ describe("github issues > #463 saving empty string array", () => { const post = new Post(); post.names = []; await connection.getRepository(Post).save(post); - const loadedPost = await connection.getRepository(Post).findOneById(1); + const loadedPost = await connection.getRepository(Post).findOne(1); loadedPost!.names.length.should.be.eql(0); }))); diff --git a/test/github-issues/485/issue-485.ts b/test/github-issues/485/issue-485.ts index 0c1ece945d..bf0eac5ad9 100644 --- a/test/github-issues/485/issue-485.ts +++ b/test/github-issues/485/issue-485.ts @@ -27,7 +27,7 @@ describe("github issues > #485 If I set the datatype of PrimaryGeneratedColumn t const post = new Post(); const savedPost = await postRepository.save(post); - const loadedPost = await postRepository.findOneById(savedPost.id); + const loadedPost = await postRepository.findOne(savedPost.id); expect(loadedPost).to.be.not.undefined; expect(loadedPost!.id).to.equal(savedPost.id); diff --git a/test/github-issues/513/issue-513.ts b/test/github-issues/513/issue-513.ts index 613666ab62..66c99e81ae 100644 --- a/test/github-issues/513/issue-513.ts +++ b/test/github-issues/513/issue-513.ts @@ -43,7 +43,7 @@ describe("github issues > #513 Incorrect time/datetime types for SQLite", () => await connection.manager.save(post); - const storedPost = await connection.manager.findOneById(Post, post.id); + const storedPost = await connection.manager.findOne(Post, post.id); expect(storedPost).to.not.be.null; storedPost!.dateTimeColumn.toDateString().should.equal(now.toDateString()); }))); @@ -73,7 +73,7 @@ describe("github issues > #513 Incorrect time/datetime types for SQLite", () => await connection.manager.save(post); - const storedPost = await connection.manager.findOneById(Post, post.id); + const storedPost = await connection.manager.findOne(Post, post.id); expect(storedPost).to.not.be.null; const expectedTimeString = DateUtils.mixedTimeToString(now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds()); diff --git a/test/github-issues/703/issue-703.ts b/test/github-issues/703/issue-703.ts index 3d49023d9b..2322497306 100644 --- a/test/github-issues/703/issue-703.ts +++ b/test/github-issues/703/issue-703.ts @@ -4,7 +4,7 @@ import {Connection} from "../../../src/connection/Connection"; import {Post} from "./entity/Post"; import {Category} from "./entity/Category"; -describe("github issues > #703 findOneById does not return an empty array on OneToMany relationship", () => { +describe("github issues > #703.findOne does not return an empty array on OneToMany relationship", () => { let connections: Connection[]; before(async () => connections = await createTestingConnections({ @@ -28,7 +28,7 @@ describe("github issues > #703 findOneById does not return an empty array on One post.categories = []; await connection.manager.save(post); - const loadedPost = await connection.getRepository(Post).findOneById(1, { + const loadedPost = await connection.getRepository(Post).findOne(1, { relations: ["categories"] }); diff --git a/test/github-issues/720/issue-720.ts b/test/github-issues/720/issue-720.ts index 95eb0c7338..59bab04f3f 100644 --- a/test/github-issues/720/issue-720.ts +++ b/test/github-issues/720/issue-720.ts @@ -59,12 +59,12 @@ describe("github issues > #720 `.save()` not updating composite key with Postgre const count2 = await connection.manager.count(Participant); expect(count2).to.be.equal(3); - const loadedParticipant1 = await connection.manager.findOneById(Participant, { order_id: 1, distance: "one" }); + const loadedParticipant1 = await connection.manager.findOne(Participant, { order_id: 1, distance: "one" }); expect(loadedParticipant1!.order_id).to.be.equal(1); expect(loadedParticipant1!.distance).to.be.equal("one"); expect(loadedParticipant1!.price).to.be.equal("150$"); - const loadedParticipant2 = await connection.manager.findOneById(Participant, { order_id: 1, distance: "two" }); + const loadedParticipant2 = await connection.manager.findOne(Participant, { order_id: 1, distance: "two" }); expect(loadedParticipant2!.order_id).to.be.equal(1); expect(loadedParticipant2!.distance).to.be.equal("two"); expect(loadedParticipant2!.price).to.be.equal("250$"); @@ -92,11 +92,13 @@ describe("github issues > #720 `.save()` not updating composite key with Postgre translation.text = "Changed Text"; await connection.manager.save(translation); - const foundTranslation = await connection.manager.getRepository(Translation).findOneById({ + const foundTranslation = await connection.manager.getRepository(Translation).findOne({ locale: { code: "US" }, - message: "1" + message: { + id: "1" + } }); expect(foundTranslation).to.be.eql({ text: "Changed Text" diff --git a/test/github-issues/836/issue-836.ts b/test/github-issues/836/issue-836.ts index df5025c680..83e1d3edc8 100644 --- a/test/github-issues/836/issue-836.ts +++ b/test/github-issues/836/issue-836.ts @@ -29,7 +29,7 @@ describe("github issues > #836 .save won't update entity when it contains OneToO credential.user = user; await connection.manager.save(credential); - // const loadedCredentials = await connection.manager.findOneById(UserCredential, 1, { + // const loadedCredentials = await connection.manager.findOne(UserCredential, 1, { // alias: "user_credential", // innerJoinAndSelect: { // user: "user_credential.user", diff --git a/test/github-issues/838/issue-838.ts b/test/github-issues/838/issue-838.ts index 80d80b7312..83157cc65c 100644 --- a/test/github-issues/838/issue-838.ts +++ b/test/github-issues/838/issue-838.ts @@ -32,7 +32,7 @@ describe.skip("github issues > #838 Time zones for timestamp columns are incorre // const results = await postgresConnection.query(`SELECT date FROM "flight" WHERE id = 1`); // console.log(results); await postgresConnection.query(`INSERT INTO "flight" ("id", "date") VALUES (1, '${testDateString}');`); - const flight = await postgresConnection.manager.findOneById(Flight, 1); + const flight = await postgresConnection.manager.findOne(Flight, 1); expect(flight!.date.toISOString()).to.equal(new Date(testDateString).toISOString()); }); diff --git a/test/github-issues/966/issue-966.ts b/test/github-issues/966/issue-966.ts index e776ee00d1..2a09202170 100644 --- a/test/github-issues/966/issue-966.ts +++ b/test/github-issues/966/issue-966.ts @@ -28,7 +28,7 @@ describe("github issues > #966 Inheritance in embeddables", () => { await repository.save(user); - const loadedUser = await repository.findOneById(user.id); + const loadedUser = await repository.findOne(user.id); expect(info).to.deep.equal(loadedUser!.info); }))); diff --git a/test/integration/sample1-simple-entity.ts b/test/integration/sample1-simple-entity.ts index 796bcc05db..d33d26f8a4 100644 --- a/test/integration/sample1-simple-entity.ts +++ b/test/integration/sample1-simple-entity.ts @@ -34,7 +34,7 @@ describe("insertion", function() { savedPost.should.be.equal(newPost); expect(savedPost.id).not.to.be.empty; - const insertedPost = await postRepository.findOneById(savedPost.id); + const insertedPost = await postRepository.findOne(savedPost.id); insertedPost!.should.be.eql({ id: savedPost.id, text: "Hello post", diff --git a/test/integration/sample2-one-to-one.ts b/test/integration/sample2-one-to-one.ts index 4685ffbf0f..65d1e4fdeb 100644 --- a/test/integration/sample2-one-to-one.ts +++ b/test/integration/sample2-one-to-one.ts @@ -87,7 +87,7 @@ describe("one-to-one", function() { expectedPost.text = savedPost.text; expectedPost.title = savedPost.title; - return postRepository.findOneById(savedPost.id).should.eventually.eql(expectedPost); + return postRepository.findOne(savedPost.id).should.eventually.eql(expectedPost); }); it("should have inserted post details in the database", function() { @@ -97,7 +97,7 @@ describe("one-to-one", function() { expectedDetails.comment = savedPost.details.comment; expectedDetails.metadata = savedPost.details.metadata; - return postDetailsRepository.findOneById(savedPost.details.id).should.eventually.eql(expectedDetails); + return postDetailsRepository.findOne(savedPost.details.id).should.eventually.eql(expectedDetails); }); it("should load post and its details if left join used", async function() { @@ -208,14 +208,14 @@ describe("one-to-one", function() { expectedPost.id = savedPost.id; expectedPost.text = savedPost.text; expectedPost.title = savedPost.title; - return postRepository.findOneById(savedPost.id).should.eventually.eql(expectedPost); + return postRepository.findOne(savedPost.id).should.eventually.eql(expectedPost); }); it("should have inserted category in the database", function() { const expectedPost = new PostCategory(); expectedPost.id = savedPost.category.id; expectedPost.name = "technology"; - return postCategoryRepository.findOneById(savedPost.category.id).should.eventually.eql(expectedPost); + return postCategoryRepository.findOne(savedPost.category.id).should.eventually.eql(expectedPost); }); it("should load post and its category if left join used", function() { diff --git a/test/integration/sample3-many-to-one.ts b/test/integration/sample3-many-to-one.ts index 537039cfd9..d569a3d6d0 100644 --- a/test/integration/sample3-many-to-one.ts +++ b/test/integration/sample3-many-to-one.ts @@ -87,7 +87,7 @@ describe("many-to-one", function() { expectedPost.text = savedPost.text; expectedPost.title = savedPost.title; - return postRepository.findOneById(savedPost.id).should.eventually.eql(expectedPost); + return postRepository.findOne(savedPost.id).should.eventually.eql(expectedPost); }); it("should have inserted post details in the database", function() { @@ -97,7 +97,7 @@ describe("many-to-one", function() { expectedDetails.comment = savedPost.details.comment; expectedDetails.metadata = savedPost.details.metadata; - return postDetailsRepository.findOneById(savedPost.details.id).should.eventually.eql(expectedDetails); + return postDetailsRepository.findOne(savedPost.details.id).should.eventually.eql(expectedDetails); }); it("should load post and its details if left join used", function() { @@ -209,14 +209,14 @@ describe("many-to-one", function() { expectedPost.id = savedPost.id; expectedPost.text = savedPost.text; expectedPost.title = savedPost.title; - return postRepository.findOneById(savedPost.id).should.eventually.eql(expectedPost); + return postRepository.findOne(savedPost.id).should.eventually.eql(expectedPost); }); it("should have inserted category in the database", function() { const expectedPost = new PostCategory(); expectedPost.id = savedPost.category.id; expectedPost.name = "technology"; - return postCategoryRepository.findOneById(savedPost.category.id).should.eventually.eql(expectedPost); + return postCategoryRepository.findOne(savedPost.category.id).should.eventually.eql(expectedPost); }); it("should load post and its category if left join used", function() { @@ -457,7 +457,7 @@ describe("many-to-one", function() { expectedPost.id = newPost.id; expectedPost.text = newPost.text; expectedPost.title = newPost.title; - return postRepository.findOneById(savedDetails.id).should.eventually.eql(expectedPost); + return postRepository.findOne(savedDetails.id).should.eventually.eql(expectedPost); }); it("should have inserted details in the database", function() { @@ -466,7 +466,7 @@ describe("many-to-one", function() { expectedDetails.comment = details.comment; expectedDetails.metadata = null; expectedDetails.authorName = null; - return postDetailsRepository.findOneById(details.id).should.eventually.eql(expectedDetails); + return postDetailsRepository.findOne(details.id).should.eventually.eql(expectedDetails); }); it("should load post and its details if left join used", function() { diff --git a/test/integration/sample4-many-to-many.ts b/test/integration/sample4-many-to-many.ts index 3f53d6b538..c675c90ed8 100644 --- a/test/integration/sample4-many-to-many.ts +++ b/test/integration/sample4-many-to-many.ts @@ -87,7 +87,7 @@ describe("many-to-many", function() { expectedPost.text = savedPost.text; expectedPost.title = savedPost.title; - return postRepository.findOneById(savedPost.id).should.eventually.eql(expectedPost); + return postRepository.findOne(savedPost.id).should.eventually.eql(expectedPost); }); it("should have inserted post details in the database", function() { @@ -97,7 +97,7 @@ describe("many-to-many", function() { expectedDetails.comment = savedPost.details[0].comment; expectedDetails.metadata = savedPost.details[0].metadata; - return postDetailsRepository.findOneById(savedPost.details[0].id).should.eventually.eql(expectedDetails); + return postDetailsRepository.findOne(savedPost.details[0].id).should.eventually.eql(expectedDetails); }); it("should load post and its details if left join used", function() { @@ -211,14 +211,14 @@ describe("many-to-many", function() { expectedPost.id = savedPost.id; expectedPost.text = savedPost.text; expectedPost.title = savedPost.title; - return postRepository.findOneById(savedPost.id).should.eventually.eql(expectedPost); + return postRepository.findOne(savedPost.id).should.eventually.eql(expectedPost); }); it("should have inserted category in the database", function() { const expectedPost = new PostCategory(); expectedPost.id = savedPost.categories[0].id; expectedPost.name = "technology"; - return postCategoryRepository.findOneById(savedPost.categories[0].id).should.eventually.eql(expectedPost); + return postCategoryRepository.findOne(savedPost.categories[0].id).should.eventually.eql(expectedPost); }); it("should load post and its category if left join used", function() { @@ -474,7 +474,7 @@ describe("many-to-many", function() { expectedPost.id = newPost.id; expectedPost.text = newPost.text; expectedPost.title = newPost.title; - return postRepository.findOneById(savedDetails.id).should.eventually.eql(expectedPost); + return postRepository.findOne(savedDetails.id).should.eventually.eql(expectedPost); }); it("should have inserted details in the database", function() { @@ -483,7 +483,7 @@ describe("many-to-many", function() { expectedDetails.comment = details.comment; expectedDetails.metadata = null; expectedDetails.authorName = null; - return postDetailsRepository.findOneById(details.id).should.eventually.eql(expectedDetails); + return postDetailsRepository.findOne(details.id).should.eventually.eql(expectedDetails); }); it("should load post and its details if left join used", function() { diff --git a/test/utils/test-utils.ts b/test/utils/test-utils.ts index d1d0c5c545..94651bcdf1 100644 --- a/test/utils/test-utils.ts +++ b/test/utils/test-utils.ts @@ -26,6 +26,12 @@ export type TestingConnectionOptions = ConnectionOptions & { */ export interface TestingOptions { + /** + * Dirname of the test directory. + * If specified, entities will be loaded from that directory. + */ + __dirname?: string; + /** * Connection name to be overridden. * This can be used to create multiple connections with single connection configuration. @@ -182,6 +188,8 @@ export function setupTestingConnections(options?: TestingOptions): ConnectionOpt newOptions.synchronize = options.schemaCreate; if (options && options.schema) newOptions.schema = options.schema; + if (options && options.__dirname) + newOptions.entities = [options.__dirname + "/entity/*{.js,.ts}"]; return newOptions; }); }