Skip to content

Commit 493c9a6

Browse files
committed
docs: update data model documentation with entity relationships and table schemas
1 parent ea5ebed commit 493c9a6

File tree

2 files changed

+78
-72
lines changed

2 files changed

+78
-72
lines changed

docs/content/2.essentials/6.data-model.md

Lines changed: 77 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -9,78 +9,83 @@ navigation:
99

1010
The Custom Fields plugin employs a **Hybrid Entity-Attribute-Value (EAV) with Type Polymorphism** design that balances flexibility with performance. Unlike traditional EAV models that suffer from type conversion overhead and poor query performance, this architecture uses typed storage columns and strategic indexing to maintain database-level optimizations while enabling dynamic field creation.
1111

12-
```mermaid
13-
erDiagram
14-
ENTITIES ||--o{ CUSTOM_FIELD_SECTIONS : "has sections for"
15-
CUSTOM_FIELD_SECTIONS ||--o{ CUSTOM_FIELDS : contains
16-
CUSTOM_FIELDS ||--o{ CUSTOM_FIELD_OPTIONS : "can have options"
17-
CUSTOM_FIELDS ||--o{ CUSTOM_FIELD_VALUES : "stores values in"
18-
ENTITIES ||--o{ CUSTOM_FIELD_VALUES : "has values via polymorphic"
19-
20-
CUSTOM_FIELD_SECTIONS {
21-
bigint id PK
22-
string entity_type
23-
string code UK
24-
string name
25-
string type
26-
string width
27-
int sort_order
28-
bool active
29-
bool system_defined
30-
json settings
31-
bigint tenant_id FK "optional"
32-
timestamps created_updated
33-
}
34-
35-
CUSTOM_FIELDS {
36-
bigint id PK
37-
bigint custom_field_section_id FK
38-
string entity_type
39-
string code UK
40-
string name
41-
string type
42-
string lookup_type
43-
string width
44-
int sort_order
45-
json validation_rules
46-
bool active
47-
bool system_defined
48-
json settings
49-
bigint tenant_id FK "optional"
50-
timestamps created_updated
51-
}
52-
53-
CUSTOM_FIELD_OPTIONS {
54-
bigint id PK
55-
bigint custom_field_id FK
56-
string name
57-
int sort_order
58-
json settings
59-
bigint tenant_id FK "optional"
60-
timestamps created_updated
61-
}
62-
63-
CUSTOM_FIELD_VALUES {
64-
bigint id PK
65-
string entity_type
66-
bigint entity_id
67-
bigint custom_field_id FK
68-
string string_value
69-
text text_value
70-
bool boolean_value
71-
bigint integer_value
72-
double float_value
73-
date date_value
74-
datetime datetime_value
75-
json json_value
76-
bigint tenant_id FK "optional"
77-
}
78-
79-
ENTITIES {
80-
bigint id PK
81-
string type "polymorphic identifier"
82-
}
83-
```
12+
### Entity Relationships
13+
14+
| Parent | Relationship | Child | Description |
15+
|--------|--------------|-------|-------------|
16+
| Entity (polymorphic) | one-to-many | `custom_field_sections` | Each entity type has its own sections |
17+
| `custom_field_sections` | one-to-many | `custom_fields` | Sections contain field definitions |
18+
| `custom_fields` | one-to-many | `custom_field_options` | Select/checkbox fields have options |
19+
| `custom_fields` | one-to-many | `custom_field_values` | Fields store values per entity instance |
20+
| Entity (polymorphic) | one-to-many | `custom_field_values` | Entity instances have field values |
21+
22+
### Table Schemas
23+
24+
::tabs
25+
::tab{label="Sections"}
26+
| Column | Type | Description |
27+
|--------|------|-------------|
28+
| `id` | bigint | Primary key |
29+
| `entity_type` | string | Polymorphic entity class |
30+
| `code` | string | Unique identifier |
31+
| `name` | string | Display name |
32+
| `type` | string | Section type |
33+
| `width` | string | Layout width |
34+
| `sort_order` | int | Display order |
35+
| `active` | bool | Enabled flag |
36+
| `system_defined` | bool | Protected from user deletion |
37+
| `settings` | json | Additional configuration |
38+
| `tenant_id` | bigint | Optional multi-tenancy |
39+
::
40+
41+
::tab{label="Fields"}
42+
| Column | Type | Description |
43+
|--------|------|-------------|
44+
| `id` | bigint | Primary key |
45+
| `custom_field_section_id` | bigint | Parent section |
46+
| `entity_type` | string | Polymorphic entity class |
47+
| `code` | string | Unique identifier |
48+
| `name` | string | Display name |
49+
| `type` | string | Field type (text, number, etc.) |
50+
| `lookup_type` | string | For lookup fields |
51+
| `width` | string | Layout width |
52+
| `sort_order` | int | Display order |
53+
| `validation_rules` | json | Laravel validation rules |
54+
| `active` | bool | Enabled flag |
55+
| `system_defined` | bool | Protected from user deletion |
56+
| `settings` | json | Type-specific configuration |
57+
| `tenant_id` | bigint | Optional multi-tenancy |
58+
::
59+
60+
::tab{label="Options"}
61+
| Column | Type | Description |
62+
|--------|------|-------------|
63+
| `id` | bigint | Primary key |
64+
| `custom_field_id` | bigint | Parent field |
65+
| `name` | string | Option label |
66+
| `sort_order` | int | Display order |
67+
| `settings` | json | Additional configuration |
68+
| `tenant_id` | bigint | Optional multi-tenancy |
69+
::
70+
71+
::tab{label="Values"}
72+
| Column | Type | Description |
73+
|--------|------|-------------|
74+
| `id` | bigint | Primary key |
75+
| `entity_type` | string | Polymorphic entity class |
76+
| `entity_id` | bigint | Polymorphic entity ID |
77+
| `custom_field_id` | bigint | Field definition |
78+
| `string_value` | string | For text fields |
79+
| `text_value` | text | For textarea fields |
80+
| `boolean_value` | bool | For checkbox fields |
81+
| `integer_value` | bigint | For integer fields |
82+
| `float_value` | double | For decimal fields |
83+
| `date_value` | date | For date fields |
84+
| `datetime_value` | datetime | For datetime fields |
85+
| `json_value` | json | For complex/array fields |
86+
| `tenant_id` | bigint | Optional multi-tenancy |
87+
::
88+
::
8489

8590
## Design Philosophy
8691

docs/package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)