{"id":18376441,"url":"https://github.com/cycle/active-record","last_synced_at":"2025-07-20T17:32:56.100Z","repository":{"id":237207430,"uuid":"794035240","full_name":"cycle/active-record","owner":"cycle","description":"Provides a simple way to work with your database using Active Record pattern and Cycle ORM.","archived":false,"fork":false,"pushed_at":"2025-03-21T18:06:51.000Z","size":1794,"stargazers_count":3,"open_issues_count":3,"forks_count":0,"subscribers_count":3,"default_branch":"1.x","last_synced_at":"2025-07-19T15:56:56.230Z","etag":null,"topics":["active-record","activerecord","cycle","cycle-orm","database","orm","php"],"latest_commit_sha":null,"homepage":"https://cycle-orm.dev","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/cycle.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"cycle"}},"created_at":"2024-04-30T10:33:18.000Z","updated_at":"2025-03-21T18:05:57.000Z","dependencies_parsed_at":"2024-04-30T12:22:13.567Z","dependency_job_id":"65ef9084-183a-4b3e-99da-dc204fcb5b3a","html_url":"https://github.com/cycle/active-record","commit_stats":null,"previous_names":["wayofdev/active-record"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/cycle/active-record","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cycle%2Factive-record","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cycle%2Factive-record/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cycle%2Factive-record/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cycle%2Factive-record/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cycle","download_url":"https://codeload.github.com/cycle/active-record/tar.gz/refs/heads/1.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cycle%2Factive-record/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266165710,"owners_count":23886668,"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","activerecord","cycle","cycle-orm","database","orm","php"],"created_at":"2024-11-06T00:23:21.021Z","updated_at":"2025-07-20T17:32:56.078Z","avatar_url":"https://github.com/cycle.png","language":"PHP","readme":"\u003cdiv align=\"center\"\u003e\n    \u003cbr\u003e\n    \u003ca href=\"https://cycle-orm.dev\" target=\"_blank\"\u003e\n        \u003cpicture\u003e\n            \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://github.com/cycle/.github/blob/main/logo/words-vector-dark.svg?raw=true\"\u003e\n            \u003cimg width=\"50%\" align=\"center\" src=\"https://github.com/cycle/.github/blob/main/logo/words-vector-light.svg?raw=true\" alt=\"CycleORM Logo\"\u003e\n        \u003c/picture\u003e\n    \u003c/a\u003e\n    \u003cbr\u003e\n    \u003cbr\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fcycle%2Factive-record%2Fbadge\u0026style=flat-square\u0026label=github%20actions)](https://github.com/cycle/active-record/actions)\n[![Total Downloads](https://img.shields.io/packagist/dt/cycle/active-record?\u0026style=flat-square)](https://packagist.org/packages/cycle/active-record)\n[![Latest Stable Version](https://img.shields.io/packagist/v/cycle/active-record?\u0026style=flat-square)](https://packagist.org/packages/cycle/active-record)\n[![Commits since latest release](https://img.shields.io/github/commits-since/cycle/active-record/latest?style=flat-square)](https://packagist.org/packages/cycle/active-record)\n[![PHP Version Require](https://poser.pugx.org/cycle/active-record/require/php?style=flat-square)](https://packagist.org/packages/cycle/active-record)\n[![Codecov Coverage](https://img.shields.io/codecov/c/github/cycle/active-record?style=flat-square\u0026logo=codecov)](https://app.codecov.io/gh/cycle/active-record)\n[![Type Coverage](https://shepherd.dev/github/cycle/active-record/coverage.svg)](https://shepherd.dev/github/cycle/active-record)\n[![Mutation testing badge](https://img.shields.io/endpoint?style=flat-square\u0026label=mutation%20score\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fcycle%2Factive-record%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/cycle/active-record/master)\n![PHP Stan Level 5 of 9](https://img.shields.io/badge/phpstan%20level-5%20of%209-yellowgreen?style=flat-square)\n[![Discord](https://img.shields.io/discord/538114875570913290?style=flat-square\u0026logo=discord\u0026labelColor=7289d9\u0026logoColor=white\u0026color=39456d)](https://discord.gg/spiralphp)\n[![Follow on Twitter (X)](https://img.shields.io/badge/-Follow-black?style=flat-square\u0026logo=X)](https://x.com/intent/follow?screen_name=SpiralPHP)\n\n\u003c/div\u003e\n\n# Active Record Implementation for Cycle ORM\n\nThis library extends Cycle ORM by integrating the [Active Record pattern](https://en.wikipedia.org/wiki/Active_record_pattern), providing developers with an intuitive, object-centric way to interact with databases.\n\nUnlike Cycle ORM's default Data Mapper pattern, which separates the in-memory object representations from database operations, Active Record combines data access and business logic in a single entity.\n\nThis allows for more straightforward and rapid development cycles, particularly for simpler CRUD operations, by enabling direct data manipulation through the object's properties and methods.\n\n\u003cbr\u003e\n\n## 🚩 Prerequisites\n\nBefore you begin, ensure your development environment meets the following requirements:\n\n- **PHP Version:** 8.2 or higher\n- One of the Cycle ORM adapters:\n  - [`spiral/cycle-bridge`](https://github.com/spiral/cycle-bridge) official Cycle ORM adapter for the [Spiral Framework](https://github.com/spiral/framework)\n  - [`yiisoft/yii-cycle`](https://github.com/yiisoft/yii-cycle) — official Cycle ORM adapter for the [Yii 3](https://www.yiiframework.com)\n  - [`wayofdev/laravel-cycle-orm-adapter`](https://github.com/wayofdev/laravel-cycle-orm-adapter) — package managed by [@wayofdev](https://github.com/wayofdev) for the [Laravel](https://laravel.com) 10.x or higher.\n\n\u003cbr\u003e\n\n## 💿 Installation\n\nThe preferred way to install this package is through [Composer](https://getcomposer.org/).\n\n```bash\ncomposer require cycle/active-record\n```\n\nAfter package install you need to, optionally, register bootloader / service-provider in your application.\n\n### → Spiral Framework\n\n\u003e [!NOTE]  \n\u003e If you are installing the package on the Spiral Framework with the [spiral-packages/discoverer](https://github.com/spiral-packages/discoverer) package, then you don't need to register bootloader by yourself. It will be registered automatically.\n\nUpdate Bootloader list in your application configuration:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace App\\Application;\n\nuse Spiral\\Cycle\\Bootloader as CycleBridge;\nuse Cycle\\ActiveRecord\\Bridge\\Spiral\\Bootloader\\ActiveRecordBootloader;\n\nclass Kernel extends \\Spiral\\Framework\\Kernel\n{\n    public function defineBootloaders(): array\n    {\n        return [\n            // ...\n        \n            // ORM\n            CycleBridge\\SchemaBootloader::class,\n            CycleBridge\\CycleOrmBootloader::class,\n            CycleBridge\\AnnotatedBootloader::class,\n            \n            // ActiveRecord\n            ActiveRecordBootloader::class,\n            \n            // ...\n        ];\n}\n```\n\nFor more information about bootloaders, refer to the [Spiral Framework documentation](https://spiral.dev/docs/framework-bootloaders/current).\n\n### → Laravel\n\n\u003e [!NOTE]\n\u003e If you are using Laravel, then you don't need to register service-provider by yourself. It will be registered automatically.\n\n### → Yii 3\n\nFor configuration instructions refer to [yii-cycle installation guide](https://github.com/yiisoft/yii-cycle/blob/master/docs/guide/en/installation.md).\n\n### → Other Frameworks\n\nThis package uses [PSR-11](https://www.php-fig.org/psr/psr-11/) compatible `container` to resolve dependencies. After container initialization you need to pass `container` instance to the static facade:\n\n```php\n\\Cycle\\ActiveRecord\\Facade::setContainer($container);\n```\n\n## 📖 Usage\n\n\u003e [!NOTE]\n\u003e For detailed usage instructions, refer to the [documentation](/docs/README.md).\n\n### → Basic Example\n\n#### Define Entity with ActiveRecord\n\n```php\nuse Cycle\\ActiveRecord\\ActiveRecord;\nuse Cycle\\Annotated\\Annotation\\Column;\nuse Cycle\\Annotated\\Annotation\\Entity;\n\n#[Entity(table: 'users')]\nclass User extends ActiveRecord\n{\n    #[Column(type: 'primary', typecast: 'int')]\n    private int $id;\n\n    #[Column(type: 'string')]    \n    private string $name;\n\n    public function __construct(string $name)\n    {\n        $this-\u003ename = $name;\n    }\n    \n    public function id(): int\n    {\n        return $this-\u003eid;\n    }\n    \n    public function name()\n    {\n        return $this-\u003ename;\n    }\n}\n```\n\n#### Create a new record\n\n```php\n$user = new User(name: 'John');\n$user-\u003esave();\n```\n\n\u003cbr\u003e\n\n## 🧪 Running Tests\n\n### → PHPUnit tests\n\nTo run tests, run the following command:\n\n```bash\nmake test\n```\n\n### → Mutation tests\n\nTo run mutation tests, using [`infection/infection`](https://github.com/infection/infection):\n\n```bash\nmake infect\n```\n\n### → Static Analysis\n\nCode quality using PHPStan:\n\n```bash\nmake lint-stan\n```\n\nand using Psalm:\n\n```bash\nmake lint-psalm\n```\n\n### → Coding Standards Fixing\n\nFix code using The PHP Coding Standards Fixer (PHP CS Fixer) to follow our standards:\n\n```bash\nmake lint-php\n```\n\n### → Lint Yaml files\n\nLint all yaml files in project:\n\n```bash\nmake lint-yaml\n```\n\n### → Lint Markdown files\n\nLint all yaml files in project:\n\n```bash\nmake lint-md\n```\n\n### → Lint GitHub Actions\n\nLint all yaml files in project:\n\n```bash\nmake lint-actions\n```\n\n\u003cbr\u003e\n\n## 🔒 Security Policy\n\nThis project has a [security policy](.github/SECURITY.md).\n\n\u003cbr\u003e\n\n## 🙌 Want to Contribute?\n\nThank you for considering contributing to the cycle community! We are open to all kinds of contributions. If you want to:\n\n- 🤔 [Suggest a feature](https://github.com/cycle/active-record/issues/new?assignees=\u0026labels=type%3A+enhancement\u0026projects=\u0026template=2-feature-request.yml\u0026title=%5BFeature%5D%3A+)\n- 🐛 [Report an issue](https://github.com/cycle/active-record/issues/new?assignees=\u0026labels=type%3A+documentation%2Ctype%3A+maintenance\u0026projects=\u0026template=1-bug-report.yml\u0026title=%5BBug%5D%3A+)\n- 📖 [Improve documentation](https://github.com/cycle/active-record/issues/new?assignees=\u0026labels=type%3A+documentation%2Ctype%3A+maintenance\u0026projects=\u0026template=4-docs-bug-report.yml\u0026title=%5BDocs%5D%3A+)\n- 👨‍💻 Contribute to the code\n\nYou are more than welcome. Before contributing, kindly check our [contribution guidelines](.github/CONTRIBUTING.md).\n\n[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg?style=for-the-badge)](https://conventionalcommits.org)\n\n\u003cbr\u003e\n\n## 🫡 Contributors\n\n\u003ca href=\"https://github.com/cycle/active-record/graphs/contributors\"\u003e\n    \u003cimg align=\"left\" src=\"https://img.shields.io/github/contributors-anon/cycle/active-record?style=for-the-badge\" alt=\"Contributors Badge\"/\u003e\n\u003c/a\u003e\n\n\u003cbr\u003e\n\u003cbr\u003e\n\n## 🌐 Social Links\n\n- **Twitter:** Follow our organization [@SpiralPHP](https://twitter.com/intent/follow?screen_name=spiralphp).\n- **Discord:** Join our community on [Discord](https://discord.gg/SpiralPHP).\n\n\u003cbr\u003e\n\n## ⚖️ License\n\n[![Licence](https://img.shields.io/github/license/wayofdev/active-record?style=for-the-badge\u0026color=blue)](./LICENSE.md)\n\n\u003cbr\u003e\n","funding_links":["https://github.com/sponsors/cycle"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcycle%2Factive-record","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcycle%2Factive-record","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcycle%2Factive-record/lists"}