immachakata/ci4-relationships
Composer 安装命令:
composer require immachakata/ci4-relationships
包简介
Easily add and manage database relationships in CodeIgniter 4
README 文档
README
A simple solution to add relationships to your Codeigniter 4 application.
Installation
You can install this library from composer by running composer install immachakata/ci4-relationships
Defining Relationships
You can define as many relationships as you want using the hasMany or hasOne functions as needed. Here's an example of defining a single relationship for a users avatar and multiple relationship for a users links.
namespace App\Models; use CodeIgniter\Model; use CI4Extensions\Database\RelationshipsTrait; class UserModel extends Model { use RelationshipsTrait; ... // declare relationships public function initialize(){ $this->hasOne('avatar', AvatarModel::class, 'user_id'); $this->hasMany('links', LinkModel::class, 'user_id'); } }
Using Relationships
When you perfom your query, explicitly mention the field name you want back as you defined in the initialize function. To do so, use the with($fieldName) function. Here's an example of retrieving the user avatar
class UserController extends BaseController { public function index(){ ... $this->respond([ 'user' => model(UserModel::class)->with('avatar')->findAll() ]); } }
Credits
Forked from michalsn/codeigniter-nested-model
immachakata/ci4-relationships 适用场景与选型建议
immachakata/ci4-relationships 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 799 次下载、GitHub Stars 达 3, 最近一次更新时间为 2023 年 09 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 immachakata/ci4-relationships 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 immachakata/ci4-relationships 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 799
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-09-25