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.
76 lines (53 loc) • 1.41 kB
text/typescript
import { Entity, ManyToOne, MikroORM, PrimaryKey, Property } from '@mikro-orm/postgresql';
()
class Address {
()
id!: number;
()
companyName: string;
()
createdAt: Date = new Date();
({ onUpdate: () => new Date() })
updatedAt: Date = new Date();
constructor(companyName: string) {
this.companyName = companyName;
}
}
()
class Customer {
()
id!: number;
()
customerNumber: string;
(() => Address)
companyAddress: Address;
()
createdAt: Date = new Date();
({ onUpdate: () => new Date() })
updatedAt: Date = new Date();
constructor(customerNumber: string, companyAddress: Address) {
this.customerNumber = customerNumber;
this.companyAddress = companyAddress;
}
}
describe('GH issue 2781', () => {
let orm: MikroORM;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [Address, Customer],
dbName: 'mikro_orm_test_2781',
});
await orm.schema.refreshDatabase();
});
afterAll(async () => {
await orm.close(true);
});
test(`GH issue 2781`, async () => {
const address1 = new Address('test1');
const customer = new Customer('100', address1);
orm.em.persist(customer);
await orm.em.flush();
customer.companyAddress = new Address('test2');
await orm.em.flush();
});
});