{"id":30450182,"url":"https://github.com/nochso/orm2","last_synced_at":"2025-08-23T13:25:47.978Z","repository":{"id":24238485,"uuid":"27631316","full_name":"nochso/ORM2","owner":"nochso","description":null,"archived":false,"fork":false,"pushed_at":"2016-02-21T10:02:28.000Z","size":114,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-04T22:03:37.144Z","etag":null,"topics":[],"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/nochso.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2014-12-06T10:55:29.000Z","updated_at":"2016-02-19T22:49:51.000Z","dependencies_parsed_at":"2022-08-25T20:40:44.538Z","dependency_job_id":null,"html_url":"https://github.com/nochso/ORM2","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/nochso/ORM2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nochso%2FORM2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nochso%2FORM2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nochso%2FORM2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nochso%2FORM2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nochso","download_url":"https://codeload.github.com/nochso/ORM2/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nochso%2FORM2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271749048,"owners_count":24814115,"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-08-23T02:00:09.327Z","response_time":69,"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":[],"created_at":"2025-08-23T13:25:41.909Z","updated_at":"2025-08-23T13:25:47.966Z","avatar_url":"https://github.com/nochso.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nochso/orm\n[![License](https://poser.pugx.org/nochso/orm/license)](https://packagist.org/packages/nochso/orm)\n[![GitHub tag](https://img.shields.io/github/tag/nochso/ORM2.svg)](https://github.com/nochso/ORM2/releases)\n[![Build Status](https://travis-ci.org/nochso/ORM2.svg?branch=master)](https://travis-ci.org/nochso/ORM2)\n[![SensioLabs Insight](https://img.shields.io/sensiolabs/i/c4694967-5a09-400f-b493-728935812c7a.svg)](https://insight.sensiolabs.com/projects/c4694967-5a09-400f-b493-728935812c7a)\n[![Coverage Status](https://coveralls.io/repos/github/nochso/ORM2/badge.svg?branch=master)](https://coveralls.io/github/nochso/ORM2?branch=master)\n[![Dependency Status](https://www.versioneye.com/user/projects/558dc123316338001e00001a/badge.svg)](https://www.versioneye.com/user/projects/558dc123316338001e00001a)\n\nA stable ActiveRecord implementation:\n \n- fluent query builder\n- tested with MySQL and SQLite\n- inspired by [Paris](http://j4mie.github.io/idiormandparis/) but with less magic for better autocompletion\n\nThe following conventions are used:\n\n- Every table requires a class inheriting from `nochso\\ORM\\Model`.\n- Class names are snaked_cased to table names by default.\n    - Otherwise you can override `protected static $_tableName`\n- Public properties of model classes correspond to column names.\n\nSelect all rows from table `blog_post` with title matching \"Hello %\" ordered by `creation_date`. Then update all titles at once.\n```php\n$posts = BlogPost::select()\n    -\u003elike('title', 'Hello %')\n    -\u003eorderAsc('creation_date')\n    -\u003eall();\nforeach ($posts as $primaryKey =\u003e $post) {\n    $post-\u003etitle .= ' and goodbye';\n}\n$posts-\u003esave();\n```\n\n## Installation\n[Get composer](https://getcomposer.org) and require `nochso/orm`.\n\n```\ncomposer require nochso/orm\n```\n\n## Example\n\n```php\nuse nochso\\ORM\\Model;\nuse nochso\\ORM\\Relation;\n\nclass User extends Model {\n    /* Actual database table name */\n    protected static $_tableName = 'user';\n    /* The Subscription class must have a field \"user_id\" to identify the user's subscriptions */\n    protected static $_relations = array(\n        'subscriptions' =\u003e array(Relation::HAS_MANY, '\\TV\\Model\\Subscription')\n    );\n    public $id;\n    public $name;\n    public $password;\n    public $token;\n\n    /* Lets you access the relation to the user's subscriptions.\n     * Names must match with the key in $_relations */\n    public $subscriptions;\n}\n```\n```php\n// Fetch a user by his name\n$john = User::select()-\u003eeq('name', 'john doe')-\u003eone();\n\n// or achieve the same using the primary key\n$sameJohn = User::select()-\u003eone($john-\u003eid);\n\necho $john-\u003ename; // 'john doe'\n\n// Change and save his name\n$john-\u003ename = 'herbert';\n$john-\u003esave();\n\n// Loads the related list of \\TV\\Model\\Subscription instances as defined in User::$_relations['subscriptions']\n$john-\u003esubscriptions-\u003efetch();\n\nif (count($john-\u003esubscriptions) \u003e 0) {\n  $john-\u003esubscriptions[0]-\u003edelete();\n}\n\n// Update certain columns of certain users\nUser::select()\n    -\u003ein('user_id', array(3, 6, 15))\n    -\u003eupdate(array('banned' =\u003e 1));\n```\n\n# Change log\nSee the [CHANGELOG](CHANGELOG.md) for the full history of changes between releases.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnochso%2Form2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnochso%2Form2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnochso%2Form2/lists"}