{"id":14987352,"url":"https://github.com/arif-rh/ci4-dynamic-model","last_synced_at":"2025-04-12T00:02:01.705Z","repository":{"id":62486853,"uuid":"256072529","full_name":"arif-rh/ci4-dynamic-model","owner":"arif-rh","description":"Creating CodeIgniter 4 Model on-the-fly with Relationship Built-in Feature","archived":false,"fork":false,"pushed_at":"2021-06-08T20:38:16.000Z","size":130,"stargazers_count":17,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T10:40:45.296Z","etag":null,"topics":["codeigniter4","codeigniter4-model","codeigniter4-relationship"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arif-rh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-16T00:53:47.000Z","updated_at":"2024-06-24T12:54:51.000Z","dependencies_parsed_at":"2022-11-02T10:02:39.959Z","dependency_job_id":null,"html_url":"https://github.com/arif-rh/ci4-dynamic-model","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arif-rh%2Fci4-dynamic-model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arif-rh%2Fci4-dynamic-model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arif-rh%2Fci4-dynamic-model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arif-rh%2Fci4-dynamic-model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arif-rh","download_url":"https://codeload.github.com/arif-rh/ci4-dynamic-model/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248497805,"owners_count":21113984,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codeigniter4","codeigniter4-model","codeigniter4-relationship"],"created_at":"2024-09-24T14:14:29.520Z","updated_at":"2025-04-12T00:02:01.657Z","avatar_url":"https://github.com/arif-rh.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DynaModel\nDynamic Model for CodeIgniter 4\n===============================\n[![Build Status](https://travis-ci.com/arif-rh/ci4-dynamic-model.svg?branch=master)](https://travis-ci.com/arif-rh/ci4-dynamic-model)  [![Coverage Status](https://coveralls.io/repos/github/arif-rh/ci4-dynamic-model/badge.svg?branch=master)](https://coveralls.io/github/arif-rh/ci4-dynamic-model?branch=master)\n\n## Feature\n* Dynamically Creating the Model on-the-fly\n* Support One-to-One / Many-to-One relationship\n* Support One-to-Many relationship\n* Can Filter data based on child/related criteria\n* Can set the order of One-to-Many relationship result based on child criteria\n\n## Installation\n\n````composer require arif-rh/ci4-dynamic-model````\n\n## Usage\n\n### Simple\n```` \n    // creating postModel on-the-fly, just pass a table name\n    $postModel = \\Arifrh\\DynaModel\\DB::table('posts');\n\n    // then you can use it, to get all posts\n    $postModel-\u003efindAll();\n````\n\n### Many-to-One Relationship\n````\n    // assume that posts always belongs to one author using author_id \n    $postModel-\u003ebelongsTo('authors);\n\n    // then you can grab author info along with posts\n    $postModel-\u003ewith('authors')-\u003efindAll();\n\n    /**\n    * by default, primary key of authors will be omit in the column result\n    * because its value already exist in the foregin key of relationship\n    * \n    * if authors has same column name with posts, then it will be aliased with prefix \"author_\"\n    * for example, both posts and authors has \"rating\" column, then it will become author_rating\n    */\n\n    // you can call only spesific column if you need, pass it on the second parameters in array\n    $postModel-\u003ewith('authors', ['name', 'rating'])-\u003efindAll(); \n    // will display all posts column, plus author name and author rating\n\n    // you can filter posts based on author criteria\n    $postModel-\u003ewith('authors')-\u003ewhereRelation('authors', ['status' =\u003e 'active'])-\u003efindAll();\n    // will display all posts only from active authors\n````\n\n### One-to-Many Relationship\n````\n    $postModel-\u003ehasMany('comments');\n\n    // this will return posts with all related comments\n    $postModel-\u003ewith('comments')-\u003efindAll();\n\n    // you can also filter posts based on comments criteria\n    $postModel-\u003ewith('comments')-\u003ewhereRelation('comments', ['status' =\u003e 'approved'])-\u003efindAll();\n    // will display all posts with approved comments only\n````\n## Testing\n\n````\n    composer test\n\n    // or\n\n    composer testdox\n\n    // analyse code\n    composer analyse\n````","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farif-rh%2Fci4-dynamic-model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farif-rh%2Fci4-dynamic-model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farif-rh%2Fci4-dynamic-model/lists"}