{"id":19613351,"url":"https://github.com/solutosoft/yii-linkmany","last_synced_at":"2025-10-08T03:58:58.550Z","repository":{"id":57055425,"uuid":"146428509","full_name":"solutosoft/yii-linkmany","owner":"solutosoft","description":"Load, validate and save automatically `hasMany` related Active Record models.","archived":false,"fork":false,"pushed_at":"2025-03-21T17:36:38.000Z","size":39,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-02T19:26:49.518Z","etag":null,"topics":["activerecord","hasmany","relations","relationships","yii2","yii2-extension"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/solutosoft.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-28T10:07:37.000Z","updated_at":"2025-03-21T17:34:49.000Z","dependencies_parsed_at":"2022-08-24T04:11:39.487Z","dependency_job_id":null,"html_url":"https://github.com/solutosoft/yii-linkmany","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/solutosoft/yii-linkmany","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solutosoft%2Fyii-linkmany","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solutosoft%2Fyii-linkmany/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solutosoft%2Fyii-linkmany/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solutosoft%2Fyii-linkmany/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/solutosoft","download_url":"https://codeload.github.com/solutosoft/yii-linkmany/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solutosoft%2Fyii-linkmany/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278886410,"owners_count":26062975,"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","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["activerecord","hasmany","relations","relationships","yii2","yii2-extension"],"created_at":"2024-11-11T10:48:03.582Z","updated_at":"2025-10-08T03:58:58.535Z","avatar_url":"https://github.com/solutosoft.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Yii LinkMany\n\nLoad, validate and save automatically `hasMany` relations.\n\n\n[![Build Status](https://github.com/solutosoft/yii-linkmany/actions/workflows/tests.yml/badge.svg)](https://github.com/solutosoft/yii-linkmany/actions)\n[![Total Downloads](https://poser.pugx.org/solutosoft/yii-linkmany/downloads.png)](https://packagist.org/packages/solutosoft/yii-linkmany)\n[![Latest Stable Version](https://poser.pugx.org/solutosoft/yii-linkmany/v/stable.png)](https://packagist.org/packages/solutosoft/yii-linkmany)\n\n\nInstallation\n------------\n\nThe preferred way to install this extension is through [composer](http://getcomposer.org/download/).\n\nEither run\n\n```\nphp composer.phar require --prefer-dist solutosoft/yii-linkmany\n```\n\nor add\n\n```json\n\"solutosoft/yii-linkmany\": \"*\"\n```\n\nto the require section of your composer.json.\n\n\nUsage\n-----\n\nThis extension provides support for ActiveRecord `hasMany` relation saving.\nThis support is granted via [[\\solutosoft\\linkmany\\LinkManyBehavior]] ActiveRecord behavior. You'll need to attach\nit to your ActiveRecord class and point the target \"has-many\" relation for it:\n\n```php\nclass Post extends ActiveRecord\n{\n    public function behaviors()\n    {\n        return [\n            'linkManyBehavior' =\u003e [\n                'class' =\u003e LinkManyBehavior::class,\n                'relations' =\u003e [\n                    'tags',\n                    'messages' =\u003e [\n                        'formName'  =\u003e 'Post[messages]',\n                        'validate' =\u003e false,\n                        'deleteOnUnlink' =\u003e false\n                    ]\n                ]\n            ],\n        ];\n    }\n\n    public function getMessages()\n    {\n        return $this-\u003ehasMany(Message::class, ['post_id' =\u003e 'id']);\n    }\n\n    public function getTags()\n    {\n        return $this-\u003ehasMany(Tag::class, ['id' =\u003e 'tag_id'])\n            -\u003eviaTable('post_tag', ['post_id' =\u003e 'id']);\n    }\n}\n```\n\nBeing attached [[\\solutosoft\\linkmany\\LinkManyBehavior]] you can load data using the method [[\\solutosoft\\linkmany\\LinkManyBehavior::fill]]\n\n```php\nuse yii\\web\\Controller;\n\nclass PostController extends Controller\n{\n    public function actionCreate()\n    {\n        $model = new Post();\n\n\n        /**\n         * $_POST could be something like:\n         * [\n         *     'tags' =\u003e [1,2]\n         *     'comments' =\u003e [\n         *         [\n         *             'subject' =\u003e 'First comment',\n         *             'content' =\u003e 'This is de fist comment',\n         *         ], [\n         *             'subject' =\u003e 'Second comment',\n         *             'content' =\u003e 'This is de second comment',\n         *         ]\n         *     ]\n         * ];\n         */\n        if ($model-\u003efill(Yii::$app-\u003erequest-\u003epost())) {\n            $model-\u003esave(); // save the model and relations\n            return $this-\u003eredirect(['view']);\n        }\n\n        return $this-\u003erender('create', [\n            'model' =\u003e $model,\n        ]);\n    }\n}\n```\n\n## Credits\n\nThis Package is inspired by:\n\n- [la-haute-societe/yii2-save-relations-behavior](https://github.com/la-haute-societe/yii2-save-relations-behavior)\n- [yii2tech/ar-linkmany](https://github.com/yii2tech/ar-linkmany).\n\nI wanted to have a combination of both. Thanks to both authors.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolutosoft%2Fyii-linkmany","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsolutosoft%2Fyii-linkmany","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolutosoft%2Fyii-linkmany/lists"}