Improve JS enum_val() with caching and single-value lookup

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-12-26 00:45:41 +00:00
parent 1abbac58e7
commit a289eecf0f
2 changed files with 36 additions and 20 deletions

View File

@@ -937,8 +937,8 @@ Integer-backed enums with model-level mapping to constants, labels, and custom p
class Project_Model extends Rsx_Model_Abstract {
public static $enums = [
'status_id' => [
1 => ['constant' => 'STATUS_ACTIVE', 'label' => 'Active', 'badge' => 'bg-success'],
2 => ['constant' => 'STATUS_ARCHIVED', 'label' => 'Archived', 'selectable' => false],
1 => ['constant' => 'STATUS_ACTIVE', 'label' => 'Active', 'badge' => 'bg-success', 'order' => 1],
2 => ['constant' => 'STATUS_ARCHIVED', 'label' => 'Archived', 'selectable' => false, 'order' => 99],
],
];
}
@@ -949,6 +949,10 @@ echo $project->status_label; // "Active"
echo $project->status_badge; // "bg-success" (custom property)
```
**Special properties**:
- `order` - Sort position in dropdowns (default: 0, lower first)
- `selectable` - Include in dropdown options (default: true). Non-selectable items excluded from `field_enum_select()` but still shown if current value.
**Migration:** Use BIGINT for enum columns, TINYINT(1) for booleans. Run `rsx:migrate:document_models` after adding enums.
### Model Fetch