From a37399adfa449297ee01fff61882be4d663b9fce Mon Sep 17 00:00:00 2001 From: Rizky Date: Tue, 25 Jun 2024 02:05:58 -0700 Subject: [PATCH] fix --- comps/md/gen/tbl-list/on_load.ts | 2 +- gen/prop/gen_prop_fields.ts | 44 +++++++++++++++++--------------- gen/prop/gen_prop_table.ts | 1 + 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/comps/md/gen/tbl-list/on_load.ts b/comps/md/gen/tbl-list/on_load.ts index 278cb50..9227635 100755 --- a/comps/md/gen/tbl-list/on_load.ts +++ b/comps/md/gen/tbl-list/on_load.ts @@ -51,7 +51,7 @@ async (arg: TableOnLoad) => { const items = await db.${table}.findMany({ select: ${JSON.stringify(select, null, 2).split("\n").join("\n ")}, orderBy: arg.orderBy || { - id: "desc", + ${pk}: "desc", }, where: { ...where, diff --git a/gen/prop/gen_prop_fields.ts b/gen/prop/gen_prop_fields.ts index 7baac84..ed69cc4 100755 --- a/gen/prop/gen_prop_fields.ts +++ b/gen/prop/gen_prop_fields.ts @@ -86,27 +86,29 @@ const get_layer = async ( if (current < depth) { if (rels) { for (const [k, v] of Object.entries(rels)) { - const to = v.to; - const from = v.from; - const r_rels = (await get_layer( - id_site, - depth, - current + 1, - arg, - v.to.table - )) as any; - options.push({ - value: JSON.stringify({ - name: k, - is_pk: false, - type: v.type, - optional: true, - relation: { from, to }, - }), - label: k, - options: r_rels, - checked: false, - }); + if (v?.to && v?.from) { + const to = v.to; + const from = v.from; + const r_rels = (await get_layer( + id_site, + depth, + current + 1, + arg, + v.to.table + )) as any; + options.push({ + value: JSON.stringify({ + name: k, + is_pk: false, + type: v.type, + optional: true, + relation: { from, to }, + }), + label: k, + options: r_rels, + checked: false, + }); + } } } } diff --git a/gen/prop/gen_prop_table.ts b/gen/prop/gen_prop_table.ts index 0fb73ca..d3d8d4f 100755 --- a/gen/prop/gen_prop_table.ts +++ b/gen/prop/gen_prop_table.ts @@ -5,6 +5,7 @@ export const gen_props_table = async () => { if (cache.length > 0) return cache; const tables = await db._schema.tables(); + console.log(tables); if (!Array.isArray(tables)) { alert("WARNING: failed to get tables from app server"); return [];