|
Text to go in the release notes:
|
Koha's object framework now supports polymorphic classing, allowing different object subclasses to be instantiated based on field values in shared database tables.
This enhancement updates `Koha::Object` and `Koha::Objects` classes to pass the original `DBIx::Class` result object to the `object_class` method, enabling dynamic class selection based on record content. This works across all standard retrieval methods including `find`, `find_or_create`, `single`, `next`, `last`, and `as_list`.
**Use cases:**
- Transport protocols (FTP/SFTP) sharing a common table but requiring protocol-specific methods
- Account lines where debits and credits share a table but need type-specific behaviour
- Any scenario where related object types share storage but require distinct method implementations
**For developers:**
To implement polymorphic classes, define a `_polymorphic_class_map` method in your `Koha::Objects` class that returns a hashref mapping field values to class names. The framework will automatically instantiate the appropriate subclass based on the stored data.
A template for implementing polymorphic classes is included in the codebase. Test::Builder has also been updated to introspect polymorphic class maps for comprehensive testing.
|