![]() |
Nested Model Relations for CodeIgniter 4 - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Addins (https://forum.codeigniter.com/forumdisplay.php?fid=34) +--- Thread: Nested Model Relations for CodeIgniter 4 (/showthread.php?tid=92250) |
Nested Model Relations for CodeIgniter 4 - michalsn - 12-31-2024 This library simplifies managing model relationships (e.g., parent-child or related entities) in CodeIgniter 4. It extends the base model functionality, making it easier to define and work with nested relations. It supports eager and lazy loading. GitHub Repository: codeigniter-nested-model Installation: Code: composer require michalsn/codeigniter-nested-model Example Usage: Initialize nad define relations. PHP Code: use Michalsn\CodeIgniterNestedModel\Relation; PHP Code: use App\Models\PostModel; The best part is that it uses the same models you normally create, so you can take full advantage of this fact. Docs: https://michalsn.github.io/codeigniter-nested-model/ RE: Nested Model Relations for CodeIgniter 4 - foxbille - 03-06-2025 Hello, Have tried it, but get a Call to undefined method App\Models\PraticienModel::initRelations exception. Can't find out why. Eric RE: Nested Model Relations for CodeIgniter 4 - michalsn - 03-06-2025 You probably forgot to add the HasRelations trait to your model. RE: Nested Model Relations for CodeIgniter 4 - foxbille - 03-06-2025 no... Have followed instructions scrupulously Started a fresh CI4 installation with composer create-project Then added codeigniter-nested-model checked everything i could (Model, Entity, controller, route) Then deleted folder and made it twice again Tried to add full path to HasRelation : use Michalsn\CodeIgniterNestedModel\Traits\HasRelation; Nothing could fix the problem RE: Nested Model Relations for CodeIgniter 4 - michalsn - 03-06-2025 The trait's name is plural - HasRelations (with an "s" at the end). RE: Nested Model Relations for CodeIgniter 4 - foxbille - 03-11-2025 I know, it's a typo in my post, script is fine. RE: Nested Model Relations for CodeIgniter 4 - foxbille - 03-13-2025 got it! use \Michalsn\CodeIgniterNestedModel\Traits\HasRelations; was outside model class definition ![]() now i get : Method "specialite()" returned an incorrect type. ("App\Models\Relation" instead of "Michalsn\CodeIgniterNestedModel\Relation") What am I doing wrong? RE: Nested Model Relations for CodeIgniter 4 - michalsn - 03-13-2025 You need to import the Relation class: PHP Code: use Michalsn\CodeIgniterNestedModel\Relation; I updated the docs - now examples have full imports of necessary classes, to prevent these types of confusion. https://michalsn.github.io/codeigniter-nested-model/basic_usage/ |