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.
90 lines (71 loc) • 1.95 kB
text/typescript
import { FullTextType, MikroORM, Collection, Entity, Index, ManyToMany, PrimaryKey, Property, Unique } from '@mikro-orm/postgresql';
class Artist {
id!: number;
name: string;
searchableName!: string;
constructor(artist: any) {
this.id = artist.id;
this.name = artist.name;
this.searchableName = artist.name;
}
}
class Song {
id!: number;
title: string;
artists = new Collection<Artist>(this);
searchableTitle!: string;
constructor(song: any) {
this.id = song.id;
this.title = song.title;
this.searchableTitle = song.title;
}
}
let orm: MikroORM;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [Song],
dbName: 'mikro_orm_test_3696',
});
await orm.schema.refreshDatabase();
});
afterAll(async () => {
await orm.close(true);
});
test('GH issue 3696', async () => {
const artist = orm.em.create(Artist, {
name: 'Taylor Swift',
searchableName: 'Taylor Swift',
});
const song = orm.em.create(Song, {
title: 'Anti-Hero',
searchableTitle: 'Anti--Hero',
});
song.artists.add(artist);
await orm.em.flush();
orm.em.clear();
const results = await orm.em.find(Song, {
searchableTitle: { $fulltext: 'anti' },
artists: { searchableName: { $fulltext: 'taylor' } },
}, { populate: ['artists'] });
expect(results).toHaveLength(1);
expect(results[0]).toMatchObject({
title: 'Anti-Hero',
searchableTitle: "'anti':1 'hero':2",
});
expect(results[0].artists[0]).toMatchObject({
name: 'Taylor Swift',
searchableName: "'swift':2 'taylor':1",
});
});