1- import { MikroORM , ArrayType , Entity , JsonType , PrimaryKey , Property } from '@mikro-orm/postgresql' ;
1+ import {
2+ ArrayType ,
3+ Entity ,
4+ JsonType ,
5+ MikroORM ,
6+ PrimaryKey ,
7+ Property ,
8+ } from '@mikro-orm/postgresql' ;
29import { mockLogger } from '../helpers' ;
310
4- type Child = {
5- email : string ;
6- } ;
7-
811@Entity ( )
9- export class User {
12+ class User {
1013
1114 @PrimaryKey ( )
1215 id ! : number ;
1316
1417 @Property ( { nullable : true , type : JsonType } )
15- children ?: Child [ ] ;
18+ children ?: any [ ] ;
19+
20+ @Property ( )
21+ email ! : string ;
1622
1723 @Property ( { type : ArrayType , nullable : true , persist : true , hydrate : true } )
1824 get childEmails ( ) : string [ ] | undefined {
@@ -36,6 +42,7 @@ beforeAll(async () => {
3642 await orm . schema . refreshDatabase ( ) ;
3743
3844 orm . em . create ( User , {
45+ email : 'test@example.com' ,
3946 children : [ {
4047 email : 'test@example.com' ,
4148 } ] ,
@@ -48,7 +55,7 @@ afterAll(async () => {
4855 await orm . close ( true ) ;
4956} ) ;
5057
51- test ( 'should not try to persist persisted getter if its value has not changed' , async ( ) => {
58+ test ( 'should not try to persist persisted getter if its value has not changed 1 ' , async ( ) => {
5259 const r = await orm . em . findAll ( User ) ;
5360
5461 const mock = mockLogger ( orm ) ;
@@ -60,3 +67,11 @@ test('should not try to persist persisted getter if its value has not changed',
6067 // child_emails is hydrated, and its value didn't change
6168 expect ( mock . mock . calls [ 1 ] [ 0 ] ) . toMatch ( 'update "user" set "children" = \'[{"email":"test@example.com"},{"email":"test2"}]\', "child_emails2" = \'{test@example.com,test2}\' where "id" = 1' ) ;
6269} ) ;
70+
71+ test ( 'should not try to persist persisted getter if its value has not changed 2' , async ( ) => {
72+ await orm . em . findOneOrFail ( User , 1 ) ;
73+ await orm . em . findOneOrFail ( User , { email : 'test@example.com' } ) ;
74+ const mock = mockLogger ( orm ) ;
75+ await orm . em . flush ( ) ;
76+ expect ( mock ) . not . toHaveBeenCalled ( ) ;
77+ } ) ;
0 commit comments