Skip to content

Commit 9b3a22d

Browse files
committed
fix: pass id of created record to the afterCreate hook and add "recordWithVirtualColumns" to this hook
1 parent 5c67a4c commit 9b3a22d

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

adminforth/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,8 @@ class AdminForth implements IAdminForth {
522522
return { error: err };
523523
}
524524

525+
const recordWithVirtualColumns = record;
526+
525527
// execute hook if needed
526528
for (const hook of listify(resource.hooks?.create?.beforeSave)) {
527529
console.log('🪲 Hook beforeSave', hook);
@@ -563,7 +565,7 @@ class AdminForth implements IAdminForth {
563565
return { error };
564566
}
565567

566-
const primaryKey = record[resource.columns.find((col) => col.primaryKey).name];
568+
const primaryKey = createdRecord[resource.columns.find((col) => col.primaryKey).name];
567569

568570
// execute hook if needed
569571
for (const hook of listify(resource.hooks?.create?.afterSave)) {
@@ -574,6 +576,7 @@ class AdminForth implements IAdminForth {
574576
record: createdRecord,
575577
adminUser,
576578
adminforth: this,
579+
recordWithVirtualColumns,
577580
extra,
578581
});
579582

adminforth/types/Back.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ export type AfterCreateSaveFunction = (params: {
568568
adminUser: AdminUser,
569569
record: any,
570570
adminforth: IAdminForth,
571+
recordWithVirtualColumns?: any,
571572
extra?: HttpExtra,
572573
}) => Promise<{ok: boolean, error?: string}>;
573574

0 commit comments

Comments
 (0)