deepkit-framework
deepkit-framework copied to clipboard
[Bug] Joined `Reference` not Expanded in Serialization in Self-Reference Senarios
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
]);
});