deepkit-framework icon indicating copy to clipboard operation
deepkit-framework copied to clipboard

[Bug] Self-Reference Fields Serialized into Nested Objects without Joinning

Open Char2sGu opened this issue 2 years ago • 2 comments

test('self-reference serialization', async () => {
    class MyEntity {
        id: number & PrimaryKey & AutoIncrement = 0;
        ref?: MyEntity & Reference; //   <---- Self-Reference Field
    }

    const databaseAdapter = new SQLiteDatabaseAdapter(':memory:');
    const schemas = [MyEntity];
    const database = new Database(databaseAdapter, schemas);
    database.logger.enableLogging();
    await database.migrate();

    const entity = new MyEntity();
    entity.ref = new MyEntity();
    await database.persist(entity);

    const entities = await database.query(MyEntity).find();
    expect(serialize<MyEntity[]>(entities)).toEqual([
        expect.anything(),
        { id: 2, ref: 1 }, //    <---- Here `ref` is serialized into an object instead of a primary key
    ]);
});

Char2sGu avatar Aug 21 '22 03:08 Char2sGu

What does "[Fix]" mean in the title?

marcj avatar Aug 21 '22 05:08 marcj

corrected 😂

Char2sGu avatar Aug 21 '22 08:08 Char2sGu

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)

marcj avatar Apr 15 '23 21:04 marcj