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.
58 lines (42 loc) • 1.2 kB
text/typescript
import { Collection, Entity, OneToMany, MikroORM, PrimaryKey, Property, ManyToOne } from '@mikro-orm/postgresql';
import { mockLogger } from '../helpers';
class User {
id!: number;
books = new Collection<Book>(this);
}
class Book {
id!: number;
parameters!: BooksParameters;
user!: User;
}
interface BooksParameters {
seasons: SeasonType[];
}
interface SeasonType {
name: string;
}
let orm: MikroORM;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [User, Book],
dbName: '4973',
});
await orm.schema.refreshDatabase();
});
afterAll(() => orm.close(true));
test('GH #4973', async () => {
const mock = mockLogger(orm);
await orm.em.findAll(User, {
where: { books: { parameters: { seasons: { $contains: [{ name: 'summer' }] } } } },
populate: ['books'],
strategy: 'select-in',
});
expect(mock.mock.calls[0][0]).toMatch(`select "u0".* from "user" as "u0" left join "book" as "b1" on "u0"."id" = "b1"."user_id" where "b1"."parameters"->'seasons' @> '[{"name":"summer"}]'`);
});