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.
85 lines (59 loc) • 1.69 kB
text/typescript
import { Entity, ManyToOne, MikroORM, PrimaryKey, Property } from '@mikro-orm/sqlite';
({ abstract: true })
abstract class BaseEntity {
()
id!: bigint;
({ onUpdate: () => new Date() })
modifiedAt: Date = new Date();
}
()
class User extends BaseEntity {
constructor(name: string) {
super();
this.name = name;
}
()
name: string;
}
()
class Position extends BaseEntity {
constructor(name: string) {
super();
this.name = name;
}
()
name: string;
}
()
class PositionBookmark extends BaseEntity {
constructor(user: User, position: Position) {
super();
this.user = user;
this.position = position;
}
(() => User)
user: User;
(() => Position)
position: Position;
}
describe('GH issue 1038', () => {
let orm: MikroORM;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [BaseEntity, User, Position, PositionBookmark],
dbName: `:memory:`,
});
await orm.schema.createSchema();
});
afterAll(async () => await orm.close(true));
test('If the PrimaryKey is BigIntType, user and Position will be updated unnecessarily', async () => {
const user1 = new User('user1');
const position1 = new Position('position1');
await orm.em.persistAndFlush([user1, position1]);
const originUserModifiedAt = user1.modifiedAt;
const positionBookmark = new PositionBookmark(user1, position1);
await orm.em.persistAndFlush([positionBookmark]);
const user = await orm.em.findOneOrFail(User, { name: user1.name });
expect(user.modifiedAt).toBe(originUserModifiedAt);
});
});