undeexcepturi
Version:
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.
71 lines (51 loc) • 1.45 kB
text/typescript
import { Collection, Entity, ManyToOne, MikroORM, OneToMany, PrimaryKey, Property } from '@mikro-orm/sqlite';
import { mockLogger } from '../helpers';
()
class Author {
()
id!: number;
({ length: 42 })
name!: string;
(() => Book, book => book.author)
books = new Collection<Book>(this);
constructor(name: string) {
this.name = name;
}
}
()
class Book {
()
id!: number;
(() => Author)
author!: Author;
({ length: 42 })
name!: string;
constructor(name: string) {
this.name = name;
}
}
describe('GH issue 1927', () => {
let orm: MikroORM;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [Author, Book],
dbName: ':memory:',
});
await orm.schema.createSchema();
});
afterAll(async () => {
await orm.close(true);
});
test(`GH issue 1927`, async () => {
await orm.em.insert(Author, { name: 'a1' });
await orm.em.insert(Book, { name: 'b1', author: 1 });
await orm.em.insert(Book, { name: 'b2', author: 1 });
await orm.em.insert(Book, { name: 'b3', author: 1 });
const result = await orm.em.execute('SELECT * FROM "book"');
const books = result.map(data => orm.em.map(Book, data));
await orm.em.populate(books, ['author']);
const mock = mockLogger(orm);
await orm.em.flush();
expect(mock.mock.calls).toHaveLength(0);
});
});