Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/michalsn/codeigniter-nested-model
Dead simple nested model relations for CodeIgniter 4 framework
https://github.com/michalsn/codeigniter-nested-model
codeigniter codeigniter4 database-relations model
Last synced: 3 months ago
JSON representation
Dead simple nested model relations for CodeIgniter 4 framework
- Host: GitHub
- URL: https://github.com/michalsn/codeigniter-nested-model
- Owner: michalsn
- License: mit
- Created: 2022-12-18T15:03:09.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-31T07:16:54.000Z (about 1 year ago)
- Last Synced: 2024-10-02T08:09:30.530Z (4 months ago)
- Topics: codeigniter, codeigniter4, database-relations, model
- Language: PHP
- Homepage:
- Size: 5.86 KB
- Stars: 9
- Watchers: 6
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CodeIgniter Nested Model
Dead simple nested model relations for CodeIgniter 4 framework. Relations are eager loaded. Each relation is one additional database query.
> [!WARNING]
> This project is experimental.### Example
```php
// app/Models/UserModel.php
['hasOne', AvatarModel::class], //'user_id', 'id'],
// many social links - relation type, model, foreign key, local key
'links' => ['hasMany', LinkModel::class], //'user_id', 'id'],
];
}
```
```php
// app/Config/Routes.php
get('nested', static function () {// get all users with avatar and links
d(model(UserModel::class)->with('avatar')->with('links')->findAll());// get user with id = 2 and all links
d(model(UserModel::class)->with('links')->find(2));// get user with id = 2 and links with type 'test'
d(model(UserModel::class)->with('links', static function () {
return model(LinkModel::class)->where('type', 'test');
})->find(2));});
...
```