Implement BEM-style enum naming and fetch() anti-aliasing policy
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -702,6 +702,8 @@ this.$sid('result_container').component('My_Component', {
|
||||
});
|
||||
```
|
||||
|
||||
**Class preservation**: Only PascalCase component names (capital start, no `__`) are replaced. Utility classes (`text-muted`), BEM child classes (`Parent__child`), and all attributes are preserved.
|
||||
|
||||
### Incremental Scaffolding
|
||||
|
||||
**Undefined components work immediately** - they render as div with the component name as a class.
|
||||
@@ -931,7 +933,7 @@ User_Model::create(['email' => $email]);
|
||||
|
||||
**CRITICAL: Read `php artisan rsx:man enum` for complete documentation before implementing.**
|
||||
|
||||
Integer-backed enums with model-level mapping to constants, labels, and custom properties.
|
||||
Integer-backed enums with model-level mapping to constants, labels, and custom properties. Uses BEM-style double underscore naming for magic properties.
|
||||
|
||||
```php
|
||||
class Project_Model extends Rsx_Model_Abstract {
|
||||
@@ -943,15 +945,30 @@ class Project_Model extends Rsx_Model_Abstract {
|
||||
];
|
||||
}
|
||||
|
||||
// Usage
|
||||
// Usage - BEM-style: field__property (double underscore)
|
||||
$project->status_id = Project_Model::STATUS_ACTIVE;
|
||||
echo $project->status_label; // "Active"
|
||||
echo $project->status_badge; // "bg-success" (custom property)
|
||||
echo $project->status_id__label; // "Active"
|
||||
echo $project->status_id__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.
|
||||
- `selectable` - Include in dropdown options (default: true). Non-selectable items excluded from `field__enum_select()` but still shown if current value.
|
||||
|
||||
**JavaScript static methods** (BEM-style double underscore):
|
||||
```js
|
||||
// Get all enum data
|
||||
Project_Model.status_id__enum()
|
||||
|
||||
// Get specific enum's metadata by ID
|
||||
Project_Model.status_id__enum(Project_Model.STATUS_ACTIVE).badge // "bg-success"
|
||||
Project_Model.status_id__enum(2).selectable // false
|
||||
|
||||
// Other methods
|
||||
Project_Model.status_id__enum_select() // For dropdowns
|
||||
Project_Model.status_id__enum_labels() // id => label map
|
||||
Project_Model.status_id__enum_ids() // Array of valid IDs
|
||||
```
|
||||
|
||||
**Migration:** Use BIGINT for enum columns, TINYINT(1) for booleans. Run `rsx:migrate:document_models` after adding enums.
|
||||
|
||||
@@ -969,7 +986,7 @@ public static function fetch($id)
|
||||
```javascript
|
||||
const project = await Project_Model.fetch(1); // Throws if not found
|
||||
const maybe = await Project_Model.fetch_or_null(999); // Returns null if not found
|
||||
console.log(project.status_label); // Enum properties populated
|
||||
console.log(project.status_id__label); // Enum properties (BEM-style)
|
||||
console.log(Project_Model.STATUS_ACTIVE); // Static enum constants
|
||||
|
||||
// Lazy relationships (requires #[Ajax_Endpoint_Model_Fetch] on relationship method)
|
||||
@@ -979,6 +996,8 @@ const tasks = await project.tasks(); // hasMany → Model[]
|
||||
|
||||
**Security**: Both `fetch()` and relationships require `#[Ajax_Endpoint_Model_Fetch]` attribute. Related models must also implement `fetch()` with this attribute.
|
||||
|
||||
**fetch() is for SECURITY, not aliasing**: The `fetch()` method exists to remove private data users shouldn't see. NEVER alias enum properties (e.g., `type_label` instead of `type_id__label`) or format dates server-side. Use the full BEM-style names and format dates on client with `Rsx_Date`/`Rsx_Time`.
|
||||
|
||||
Details: `php artisan rsx:man model_fetch`
|
||||
|
||||
### Migrations
|
||||
|
||||
Reference in New Issue
Block a user