Closed Char2sGu closed 1 year ago
test('joinWith', async () => { // Condition1: Self-Reference Entity class MyEntity { id: number & PrimaryKey & AutoIncrement = 0; ref?: MyEntity & Reference; refs?: MyEntity[] & BackReference; } const database = new Database(new SQLiteDatabaseAdapter(':memory:'), [MyEntity]); database.logger.enableLogging(); await database.migrate(); const entity1 = new MyEntity(); const entity2 = new MyEntity(); entity1.ref = entity2; await database.persist(entity1, entity2); // Condition2: Both Reference and BackReference fields are Joined. const result = await database .query(MyEntity) .joinWith('ref') .joinWith('refs') .find(); expect(serialize<MyEntity[]>(result)).toEqual([ { id: 1, ref: null, refs: [{ id: 2, ref: 1 }] }, { id: 2, ref: { id: 1, ref: null } }, // <--- Bug: Here `ref` is `null` instead of a nested object ]); });
Thanks @TheNightmareX, this should be fixed in master. Please check it out and let me know. (tests added in https://github.com/deepkit/deepkit-framework/commit/aa90b17a28cdf0b081736579c7463920eb97412a)