Add transparent type_ref conversion in WHERE clauses

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-12-27 23:49:21 +00:00
parent 56680840a1
commit 94dce4f021
2 changed files with 198 additions and 0 deletions

View File

@@ -89,12 +89,32 @@ The `Type_Ref_Registry::register_morph_map()` method is called during framework
$model->attachable_type = class_basename($related);
```
## Query Builder Integration
The `RestrictedEloquentBuilder` automatically converts type_ref columns in WHERE clauses:
```php
// All of these work transparently - class names auto-converted to IDs
File_Attachment_Model::where('fileable_type', 'Contact_Model')->get();
File_Attachment_Model::where('fileable_type', '=', 'Contact_Model')->get();
File_Attachment_Model::where(['fileable_type' => 'Contact_Model'])->get();
// whereIn also works
File_Attachment_Model::whereIn('fileable_type', ['Contact_Model', 'Project_Model'])->get();
// Integer IDs still work (pass-through)
File_Attachment_Model::where('fileable_type', 42)->get();
```
Supported methods: `where()`, `orWhere()`, `whereIn()`, `orWhereIn()`, `whereNotIn()`, `orWhereNotIn()`
## Important Notes
- **Simple Names Only**: Always use simple class names (`Contact_Model`), never FQCNs
- **Auto-Registration**: New classes are auto-registered when first used
- **Transparent**: After setup, code works identically to VARCHAR storage
- **Laravel Compatible**: Works with `morphTo()`, `morphMany()`, etc.
- **Query Logs**: Show integer IDs, not class names (expected behavior)
## Reference