Skip to content

Commit

Permalink
feat(core): add the offset into FindOneOptions (#3574)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Adámek <banan23@gmail.com>
  • Loading branch information
Phosphorus-M and B4nan committed Oct 11, 2022
1 parent 633489b commit 9d5d457
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/drivers/IDatabaseDriver.ts
Expand Up @@ -118,7 +118,7 @@ export interface FindOptions<T, P extends string = never> {
connectionType?: ConnectionType;
}

export interface FindOneOptions<T extends object, P extends string = never> extends Omit<FindOptions<T, P>, 'limit' | 'offset' | 'lockMode'> {
export interface FindOneOptions<T extends object, P extends string = never> extends Omit<FindOptions<T, P>, 'limit' | 'lockMode'> {
lockMode?: LockMode;
lockVersion?: number | Date;
}
Expand Down
33 changes: 33 additions & 0 deletions tests/issues/GH3292.test.ts
@@ -0,0 +1,33 @@
import type { MikroORM } from '@mikro-orm/core';
import { initORMPostgreSql } from '../bootstrap';
import { Author2, Book2 } from '../entities-sql';

let orm: MikroORM;

beforeAll(async () => orm = await initORMPostgreSql());
beforeEach(async () => orm.schema.clearDatabase());
afterAll(() => orm.close(true));

test('test findOne without a offset', async () => {
const author = new Author2('Bartleby', 'bartelby@writer.org');
const book = new Book2('My Life on The Wall, part 1', author);
new Book2('My Life on The Wall, part 2', author);

await orm.em.fork().persistAndFlush(author);

const myBook = await orm.em.findOne(Book2, {});

expect(myBook?.title).toEqual(book.title);
});

test('test findOne but with a offset', async () => {
const author = new Author2('Bartleby', 'bartelby@writer.org');
new Book2('My Life on The Wall, part 1', author);
const book2 = new Book2('My Life on The Wall, part 2', author);

await orm.em.fork().persistAndFlush(author);

const myBook = await orm.em.findOne(Book2, {}, { offset: 1 });

expect(myBook?.title).toEqual(book2.title);
});

0 comments on commit 9d5d457

Please sign in to comment.