Standardize enum static methods across PHP and JavaScript
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -73,26 +73,47 @@ PHP MAGIC PROPERTIES (Instance)
|
||||
echo $user->status_badge; // "bg-success"
|
||||
echo $user->status_visible_frontend; // true
|
||||
|
||||
PHP STATIC METHODS
|
||||
STATIC METHODS (PHP and JavaScript)
|
||||
|
||||
Model::field_enum()
|
||||
Returns all enum definitions for a field with all properties:
|
||||
These four methods are available as static methods on model classes in both PHP
|
||||
and JavaScript. The JavaScript stubs are auto-generated to mirror PHP behavior.
|
||||
|
||||
$statuses = User_Model::status_id_enum();
|
||||
Model::field_enum_val()
|
||||
Returns all enum definitions for a field with full metadata:
|
||||
|
||||
$statuses = User_Model::status_id_enum_val();
|
||||
// [1 => ['constant' => 'STATUS_ACTIVE', 'label' => 'Active', ...], ...]
|
||||
|
||||
// JavaScript equivalent:
|
||||
const statuses = User_Model.status_id_enum_val();
|
||||
|
||||
Model::field_enum_select()
|
||||
Returns key/label pairs for dropdowns, respecting 'selectable' and 'order':
|
||||
Returns selectable items for dropdowns (respects 'selectable' and 'order'):
|
||||
|
||||
$options = User_Model::status_id_enum_select();
|
||||
// [1 => 'Active', 2 => 'Inactive']
|
||||
// [1 => 'Active', 2 => 'Inactive'] (excludes selectable: false items)
|
||||
|
||||
// JavaScript equivalent:
|
||||
const options = User_Model.status_id_enum_select();
|
||||
|
||||
Model::field_enum_labels()
|
||||
Returns simple id => label map (all items, ignores selectable flag):
|
||||
|
||||
$labels = User_Model::status_id_enum_labels();
|
||||
// [1 => 'Active', 2 => 'Inactive', 3 => 'Archived']
|
||||
|
||||
// JavaScript equivalent:
|
||||
const labels = User_Model.status_id_enum_labels();
|
||||
|
||||
Model::field_enum_ids()
|
||||
Returns all possible enum values as an array:
|
||||
Returns array of all valid enum IDs:
|
||||
|
||||
$ids = User_Model::status_id_enum_ids();
|
||||
// [1, 2, 3]
|
||||
|
||||
// JavaScript equivalent:
|
||||
const ids = User_Model.status_id_enum_ids();
|
||||
|
||||
PHP CONSTANTS
|
||||
|
||||
Constants are automatically generated via rsx:migrate:document_models command:
|
||||
@@ -117,10 +138,11 @@ JAVASCRIPT ACCESS
|
||||
Project_Model.STATUS_ACTIVE // 2
|
||||
Project_Model.STATUS_PLANNING // 1
|
||||
|
||||
Static Methods
|
||||
Project_Model.status_enum_val() // Full enum definitions
|
||||
Project_Model.status_enum_select() // Filtered for dropdowns
|
||||
Project_Model.status_label_list() // All labels keyed by value
|
||||
Static Methods (same as PHP - see STATIC METHODS section above)
|
||||
Project_Model.status_enum_val() // Full enum definitions with metadata
|
||||
Project_Model.status_enum_select() // Selectable items for dropdowns
|
||||
Project_Model.status_enum_labels() // Simple id => label map
|
||||
Project_Model.status_enum_ids() // Array of valid IDs
|
||||
|
||||
Instance Properties (after fetch)
|
||||
const project = await Project_Model.fetch(1);
|
||||
|
||||
Reference in New Issue
Block a user