mirror of
https://github.com/bknd-io/bknd/
synced 2026-08-03 08:36:01 +00:00
fix: handle correct type conversion for relation fields
Updated `RelationField` to dynamically determine the type based on `target_field_type`. Added a test for proper TypeScript generation with text primary fields in system entities.
This commit is contained in:
@@ -21,4 +21,34 @@ describe("EntityTypescript", () => {
|
||||
const et = new EntityTypescript(schema.proto.withConnection(new DummyConnection()));
|
||||
expect(et.toString()).toContain('users?: DB["users"];');
|
||||
});
|
||||
|
||||
it("should generate correct typescript for system entities with uuid primary field", () => {
|
||||
const schema = proto.em(
|
||||
{
|
||||
test: proto.entity(
|
||||
"test",
|
||||
{
|
||||
name: proto.text(),
|
||||
},
|
||||
{
|
||||
primary_format: "uuid",
|
||||
},
|
||||
),
|
||||
users: proto.systemEntity(
|
||||
"users",
|
||||
{
|
||||
name: proto.text(),
|
||||
},
|
||||
{
|
||||
primary_format: "uuid",
|
||||
},
|
||||
),
|
||||
},
|
||||
({ relation }, { test, users }) => {
|
||||
relation(test).manyToOne(users);
|
||||
},
|
||||
);
|
||||
const et = new EntityTypescript(schema.proto.withConnection(new DummyConnection()));
|
||||
expect(et.toString()).toContain("users_id?: string;");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user