Nested Model Relations for CodeIgniter 4 |
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/
Hello,
Have tried it, but get a Call to undefined method App\Models\PraticienModel::initRelations exception. Can't find out why. Eric
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
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?
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-n...sic_usage/ |
Welcome Guest, Not a member yet? Register Sign In |