{"id":28323466,"url":"https://github.com/jsas4coding/yii2-m2m-behavior","last_synced_at":"2025-06-24T00:31:08.526Z","repository":{"id":288453784,"uuid":"968058611","full_name":"jsas4coding/yii2-m2m-behavior","owner":"jsas4coding","description":"Yii2 behavior for managing many-to-many (M:N) relationships using ActiveRecord with virtual attributes, auto-syncing, and full test coverage.","archived":false,"fork":false,"pushed_at":"2025-04-21T23:38:53.000Z","size":115,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-02T00:56:30.044Z","etag":null,"topics":["active-record","behavior","junction-table","many-to-many","php","relations","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jsas4coding.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":"ROADMAP.md","authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-17T12:44:59.000Z","updated_at":"2025-04-28T23:42:21.000Z","dependencies_parsed_at":"2025-04-18T06:39:11.829Z","dependency_job_id":"94db5339-f751-489c-a017-5e58af0b1ac6","html_url":"https://github.com/jsas4coding/yii2-m2m-behavior","commit_stats":null,"previous_names":["jonatas-sas/yii2-m2m-behavior","jsas4coding/yii2-m2m-behavior"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/jsas4coding/yii2-m2m-behavior","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsas4coding%2Fyii2-m2m-behavior","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsas4coding%2Fyii2-m2m-behavior/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsas4coding%2Fyii2-m2m-behavior/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsas4coding%2Fyii2-m2m-behavior/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jsas4coding","download_url":"https://codeload.github.com/jsas4coding/yii2-m2m-behavior/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsas4coding%2Fyii2-m2m-behavior/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261582555,"owners_count":23180610,"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":["active-record","behavior","junction-table","many-to-many","php","relations","yii2","yii2-extension"],"created_at":"2025-05-25T16:14:08.892Z","updated_at":"2025-06-24T00:31:08.520Z","avatar_url":"https://github.com/jsas4coding.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Yii2 Many to Many Behavior\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.php.net/releases/8.1/en.php\" title=\"PHP Version 8.1+\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\u003cimg src=\"https://img.shields.io/badge/PHP-8.1+-8892BF.svg?style=flat-square\u0026logo=php\" alt=\"PHP 8.1+\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://www.yiiframework.com/\" title=\"Yii Framework Website\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\u003cimg src=\"https://img.shields.io/badge/Powered_by-Yii_Framework-green.svg?style=flat-square\" alt=\"Powered by Yii Framework\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://packagist.org/packages/jonatas-sas/yii2-m2m-behavior\" title=\"View on Packagist\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\u003cimg src=\"https://img.shields.io/packagist/v/jonatas-sas/yii2-m2m-behavior.svg?style=flat-square\" alt=\"Packagist Version\"\u003e\u003c/a\u003e\n  \u003ca href=\"LICENSE\" title=\"View License\"\u003e\u003cimg src=\"https://img.shields.io/packagist/l/jonatas-sas/yii2-m2m-behavior.svg?style=flat-square\" alt=\"License\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/jonatas-sas/yii2-m2m-behavior/actions/workflows/lint.yml\" title=\"Lint Workflow\"\u003e\u003cimg src=\"https://github.com/jonatas-sas/yii2-m2m-behavior/actions/workflows/lint.yml/badge.svg\" alt=\"Lint Status\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/jonatas-sas/yii2-m2m-behavior/actions/workflows/static.yml\" title=\"Static Analysis Status\"\u003e\u003cimg src=\"https://github.com/jonatas-sas/yii2-m2m-behavior/actions/workflows/static.yml/badge.svg\" alt=\"Static Analysis\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/jonatas-sas/yii2-m2m-behavior/actions/workflows/test.yml\" title=\"Test Workflow\"\u003e\u003cimg src=\"https://github.com/jonatas-sas/yii2-m2m-behavior/actions/workflows/test.yml/badge.svg\" alt=\"Tests Status\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/jonatas-sas/yii2-m2m-behavior/actions/workflows/security.yml\" title=\"Security Scan\"\u003e\u003cimg src=\"https://github.com/jonatas-sas/yii2-m2m-behavior/actions/workflows/security.yml/badge.svg\" alt=\"Security Status\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/jonatas-sas/yii2-m2m-behavior/actions/workflows/dependabot/dependabot-updates\" title=\"Dependabot Updates\"\u003e\u003cimg src=\"https://github.com/jonatas-sas/yii2-m2m-behavior/actions/workflows/dependabot/dependabot-updates/badge.svg\" alt=\"Dependabot\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://codecov.io/gh/jonatas-sas/yii2-m2m-behavior\" title=\"Code Coverage\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\u003cimg src=\"https://codecov.io/gh/jonatas-sas/yii2-m2m-behavior/branch/main/graph/badge.svg\" alt=\"Coverage\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://packagist.org/packages/jonatas-sas/yii2-m2m-behavior/stats\" title=\"Total Downloads\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\u003cimg src=\"https://img.shields.io/packagist/dt/jonatas-sas/yii2-m2m-behavior.svg?style=flat-square\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/jonatas-sas/yii2-m2m-behavior/issues\" title=\"Open Issues\"\u003e\u003cimg src=\"https://img.shields.io/github/issues/jonatas-sas/yii2-m2m-behavior.svg?style=flat-square\" alt=\"Open Issues\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/jonatas-sas/yii2-m2m-behavior/pulls\" title=\"Open Pull Requests\"\u003e\u003cimg src=\"https://img.shields.io/github/issues-pr/jonatas-sas/yii2-m2m-behavior.svg?style=flat-square\" alt=\"Open Pull Requests\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nA reusable and robust behavior for managing many-to-many (M2M) relationships in **Yii2 ActiveRecord** using virtual attributes.\n\n\u003e 🧩 Inspired by the archived [`yii2tech/ar-linkmany`](https://github.com/yii2tech/ar-linkmany) package by [Paul Klimov](https://github.com/PaulKlimov), now extended with modern improvements, full test coverage, and long-term support.\n\n---\n\n## 📦 Installation\n\n```bash\ncomposer require jonatas-sas/yii2-m2m-behavior\n```\n\n---\n\n## 📚 Documentation\n\n- 📘 [English Docs](docs/index.md)\n- 🇧🇷 [Documentação em Português](docs/index.pt_BR.md)\n\n---\n\n## 🚀 Overview\n\nYii2 Many to Many Behavior helps you:\n\n- Manage M2M relations using **virtual attributes** (e.g. `tagIds`).\n- Automatically sync relations on `insert`, `update`, and `delete`.\n- Control deletion of junction table rows (`deleteOnUnlink`).\n- Add **extra columns** to junction records (e.g. timestamps or metadata).\n- Integrate smoothly into **ActiveForm**, **GridView**, and **DetailView**.\n\n---\n\n## 🛠 Example Usage (PHP 8.1+)\n\n```php\nuse yii\\db\\ActiveRecord;\nuse yii\\db\\ActiveQuery;\nuse odara\\yii\\behaviors\\LinkManyToManyBehavior;\n\n/**\n * @property int        $id\n * @property string     $name\n *\n * @property-read Tag[] $tags\n * @property int[]      $tagIds\n */\nclass Item extends ActiveRecord\n{\n    /**\n     * @inheritdoc\n     */\n    public function behaviors()\n    {\n        return [\n            'tags' =\u003e [\n                'class' =\u003e LinkManyToManyBehavior::class,\n                'relation' =\u003e 'tags',\n                'referenceAttribute' =\u003e 'tagIds',\n                'deleteOnUnlink' =\u003e true,\n                'extraColumns' =\u003e [\n                    'source' =\u003e 'admin',\n                    'created_at' =\u003e static fn (): int =\u003e time(),\n                ],\n            ],\n        ];\n    }\n\n    /**\n     * Returns the relation between Item and Tag models.\n     *\n     * @return ActiveQuery\n     */\n    public function getTags(): ActiveQuery\n    {\n        return $this-\u003ehasMany(Tag::class, ['id' =\u003e 'tag_id'])\n            -\u003eviaTable('item_tag', ['item_id' =\u003e 'id']);\n    }\n}\n```\n\n### Example Form Field\n\n```php\necho $form-\u003efield($model, 'tagIds')-\u003echeckboxList(\n    Tag::find()\n        -\u003eselect(['name', 'id'])\n        -\u003eindexBy('id')\n        -\u003ecolumn()\n);\n```\n\n---\n\n## 🤝 Contributing\n\nFound a bug or want to suggest an improvement?\n\n- Read the [Contributing Guide](CONTRIBUTING.md)\n- Follow [PSR-12](https://www.php-fig.org/psr/psr-12/) and [Yii2 coding practices](https://www.yiiframework.com/doc/guide/2.0/en)\n\n---\n\n## 🛡 License\n\nYii2 Many to Many Behavior is released under the MIT License.\n\n---\n\n## 💙 Credits\n\nMaintained by the Yii2 community.\\\nInspired by the Yii2Tech package and rebuilt with care for modern development.\n\n---\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.yiiframework.com\" title=\"Yii Framework\" target=\"_blank\"\u003e\u003cimg src=\"https://www.yiiframework.com/image/design/logo/yii3_full_for_dark.svg\" alt=\"Yii Framework\" width=\"300\" title=\"Yii Framework\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsas4coding%2Fyii2-m2m-behavior","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsas4coding%2Fyii2-m2m-behavior","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsas4coding%2Fyii2-m2m-behavior/lists"}