diff --git a/adminforth/types/Common.ts b/adminforth/types/Common.ts
index 56429139d..b3fe73c0e 100644
--- a/adminforth/types/Common.ts
+++ b/adminforth/types/Common.ts
@@ -540,9 +540,14 @@ export type ShowInResolved = {
[key in AdminForthResourcePages]: boolean
}
-
-export interface AdminForthForeignResourceCommon {
+export interface AdminForthPolymorphicForeignResource {
resourceId: string,
+ whenValue: string,
+}
+export interface AdminForthForeignResourceCommon {
+ resourceId?: string,
+ polymorphicResources?: Array
,
+ polymorphicOn?: string,
unsetLabel?: string,
}
diff --git a/dev-demo/index.ts b/dev-demo/index.ts
index 978729e16..35b8e5a28 100644
--- a/dev-demo/index.ts
+++ b/dev-demo/index.ts
@@ -13,6 +13,9 @@ import usersResource from './resources/users.js';
// import gamesUsersResource from './resources/games_users.js';
// import gamesResource from './resources/games.js';
import translationsResource from './resources/translation.js';
+import clinicsResource from './resources/clinics.js';
+import providersResource from './resources/providers.js';
+import apiKeysResource from './resources/api_keys.js';
import CompletionAdapterOpenAIChatGPT from '../adapters/adminforth-completion-adapter-open-ai-chat-gpt/index.js';
// const ADMIN_BASE_URL = '/portal';
@@ -203,6 +206,9 @@ export const admin = new AdminForth({
apartmentBuyersResource,
usersResource,
descriptionImageResource,
+ clinicsResource,
+ providersResource,
+ apiKeysResource,
// gamesResource,
// gamesUsersResource,
// gameResource,
@@ -264,6 +270,21 @@ export const admin = new AdminForth({
// resourceId: 'game',
// },
+ {
+ label: 'Clinics',
+ icon: 'flowbite:building-solid',
+ resourceId: 'clinics',
+ },
+ {
+ label: 'Providers',
+ icon: 'flowbite:user-solid',
+ resourceId: 'providers',
+ },
+ {
+ label: 'API Keys',
+ icon: 'flowbite:search-outline',
+ resourceId: 'api_keys',
+ },
{
label: 'Clicks',
icon: 'flowbite:search-outline',
diff --git a/dev-demo/migrations/20250227084330_polyamorphic_tables_init/migration.sql b/dev-demo/migrations/20250227084330_polyamorphic_tables_init/migration.sql
new file mode 100644
index 000000000..ae01e5a66
--- /dev/null
+++ b/dev-demo/migrations/20250227084330_polyamorphic_tables_init/migration.sql
@@ -0,0 +1,19 @@
+-- CreateTable
+CREATE TABLE "clinics" (
+ "id" TEXT NOT NULL PRIMARY KEY,
+ "name" TEXT NOT NULL
+);
+
+-- CreateTable
+CREATE TABLE "providers" (
+ "id" TEXT NOT NULL PRIMARY KEY,
+ "name" TEXT NOT NULL
+);
+
+-- CreateTable
+CREATE TABLE "api_keys" (
+ "id" TEXT NOT NULL PRIMARY KEY,
+ "name" TEXT NOT NULL,
+ "owner" TEXT,
+ "owner_id" TEXT
+);
diff --git a/dev-demo/resources/api_keys.ts b/dev-demo/resources/api_keys.ts
new file mode 100644
index 000000000..cd055ae8b
--- /dev/null
+++ b/dev-demo/resources/api_keys.ts
@@ -0,0 +1,64 @@
+import { AdminForthDataTypes, AdminForthResourceInput } from "../../adminforth";
+import { v1 as uuid } from "uuid";
+
+export default {
+ dataSource: 'maindb',
+ table: 'api_keys',
+ resourceId: 'api_keys',
+ label: 'API Keys',
+ recordLabel: (r: any) => `🔑 ${r.name}`,
+ columns: [
+ {
+ name: 'id',
+ label: 'ID',
+ primaryKey: true,
+ fillOnCreate: ({ initialRecord, adminUser }: any) => uuid(),
+ showIn: {
+ create: false,
+ edit: false,
+ },
+ components: {
+ list: "@/renderers/CompactUUID.vue",
+ },
+ },
+ {
+ name: 'name',
+ type: AdminForthDataTypes.STRING,
+ required: true,
+ maxLength: 255,
+ },
+ {
+ name: 'owner',
+ type: AdminForthDataTypes.STRING,
+ enum: [
+ {
+ value: 'clinic',
+ label: 'Clinic',
+ },
+ {
+ value: 'provider',
+ label: 'Provider',
+ },
+ ],
+ showIn: { create: false, edit: false },
+ },
+ {
+ name: 'owner_id',
+ foreignResource: {
+ polymorphicResources: [
+ {
+ resourceId: 'clinics',
+ whenValue: 'clinic',
+ },
+ {
+ resourceId: 'providers',
+ whenValue: 'provider',
+ },
+ ],
+ polymorphicOn: 'owner',
+ },
+ },
+ ],
+ plugins: [],
+ options: {},
+} as AdminForthResourceInput;
\ No newline at end of file
diff --git a/dev-demo/resources/clinics.ts b/dev-demo/resources/clinics.ts
new file mode 100644
index 000000000..0e32296f9
--- /dev/null
+++ b/dev-demo/resources/clinics.ts
@@ -0,0 +1,33 @@
+import { AdminForthDataTypes, AdminForthResourceInput } from "../../adminforth";
+import { v1 as uuid } from "uuid";
+
+export default {
+ dataSource: 'maindb',
+ table: 'clinics',
+ resourceId: 'clinics',
+ label: 'Clinics',
+ recordLabel: (r: any) => `🏥 ${r.name}`,
+ columns: [
+ {
+ name: 'id',
+ label: 'ID',
+ primaryKey: true,
+ fillOnCreate: ({ initialRecord, adminUser }: any) => uuid(),
+ showIn: {
+ create: false,
+ edit: false,
+ },
+ components: {
+ list: "@/renderers/CompactUUID.vue",
+ },
+ },
+ {
+ name: 'name',
+ type: AdminForthDataTypes.STRING,
+ required: true,
+ maxLength: 255,
+ },
+ ],
+ plugins: [],
+ options: {},
+} as AdminForthResourceInput;
\ No newline at end of file
diff --git a/dev-demo/resources/providers.ts b/dev-demo/resources/providers.ts
new file mode 100644
index 000000000..ed3ffc6d0
--- /dev/null
+++ b/dev-demo/resources/providers.ts
@@ -0,0 +1,33 @@
+import { AdminForthDataTypes, AdminForthResourceInput } from "../../adminforth";
+import { v1 as uuid } from "uuid";
+
+export default {
+ dataSource: 'maindb',
+ table: 'providers',
+ resourceId: 'providers',
+ label: 'Providers',
+ recordLabel: (r: any) => `👨⚕️ ${r.name}`,
+ columns: [
+ {
+ name: 'id',
+ label: 'ID',
+ primaryKey: true,
+ fillOnCreate: ({ initialRecord, adminUser }: any) => uuid(),
+ showIn: {
+ create: false,
+ edit: false,
+ },
+ components: {
+ list: "@/renderers/CompactUUID.vue",
+ },
+ },
+ {
+ name: 'name',
+ type: AdminForthDataTypes.STRING,
+ required: true,
+ maxLength: 255,
+ },
+ ],
+ plugins: [],
+ options: {},
+} as AdminForthResourceInput;
\ No newline at end of file
diff --git a/dev-demo/schema.prisma b/dev-demo/schema.prisma
index 2bcd0ca0e..3d41cd3ac 100644
--- a/dev-demo/schema.prisma
+++ b/dev-demo/schema.prisma
@@ -104,4 +104,21 @@ model apartment_buyers {
contact_date DateTime?
contact_time DateTime?
realtor_id String?
+}
+
+model clinics {
+ id String @id
+ name String
+}
+
+model providers {
+ id String @id
+ name String
+}
+
+model api_keys {
+ id String @id
+ name String
+ owner String?
+ owner_id String?
}
\ No newline at end of file