{"id":13684421,"url":"https://github.com/UseMuffin/Sti","last_synced_at":"2025-04-30T20:33:54.323Z","repository":{"id":57021734,"uuid":"50006883","full_name":"UseMuffin/Sti","owner":"UseMuffin","description":"Single Table Inheritance for CakePHP ORM.","archived":false,"fork":false,"pushed_at":"2023-11-26T04:11:27.000Z","size":52,"stargazers_count":6,"open_issues_count":3,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-09T12:51:03.063Z","etag":null,"topics":[],"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/UseMuffin.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2016-01-20T05:27:31.000Z","updated_at":"2023-04-02T10:15:56.000Z","dependencies_parsed_at":"2023-11-26T05:20:44.030Z","dependency_job_id":"bca7aac6-1926-484f-8bd0-069d303794f2","html_url":"https://github.com/UseMuffin/Sti","commit_stats":{"total_commits":26,"total_committers":4,"mean_commits":6.5,"dds":0.5384615384615384,"last_synced_commit":"c3fc14a51fd520b1da709b45ca68f73e4aa5d381"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UseMuffin%2FSti","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UseMuffin%2FSti/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UseMuffin%2FSti/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UseMuffin%2FSti/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/UseMuffin","download_url":"https://codeload.github.com/UseMuffin/Sti/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251777779,"owners_count":21642224,"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":[],"created_at":"2024-08-02T14:00:33.346Z","updated_at":"2025-04-30T20:33:54.061Z","avatar_url":"https://github.com/UseMuffin.png","language":"PHP","funding_links":[],"categories":["ORM / Database / Datamapping"],"sub_categories":[],"readme":"# Sti\n\n[![Build Status](https://img.shields.io/travis/UseMuffin/Sti/master.svg?style=flat-square)](https://travis-ci.org/UseMuffin/Sti)\n[![Coverage](https://img.shields.io/coveralls/github/UseMuffin/Sti?style=flat-square)](https://codecov.io/gh/UseMuffin/Sti)\n[![Total Downloads](https://img.shields.io/packagist/dt/muffin/sti.svg?style=flat-square)](https://packagist.org/packages/muffin/sti)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE)\n\nSingle Table Inheritance for CakePHP ORM.\n\n\u003e [...] a way to emulate object-oriented inheritance in a relational database. When mapping from a database\n\u003e table to an object in an object-oriented language, a field in the database identifies what class in the\n\u003e hierarchy the object belongs to.\n\n(source: [Wikipedia][1])\n\n## Install\n\nUsing [Composer][composer]:\n\n```\ncomposer require muffin/sti\n```\n\nYou then need to load the plugin. You can use the console command:\n\n```\nbin/cake plugin load Muffin/Sti\n```\n\n## Usage\n\n```php\n\u003c?php // src/Model/Table/CooksTable.php\nnamespace App\\Model\\Table;\n\nuse Cake\\ORM\\Table;\n\nclass CooksTable extends Table\n{\n    public function initialize($config)\n    {\n        $this-\u003esetTable('sti_cooks');\n        $this-\u003eaddBehavior('Muffin/Sti.Sti', [\n            'typeMap' =\u003e [\n                'chef' =\u003e 'App\\Model\\Entity\\Chef',\n                'baker' =\u003e 'App\\Model\\Entity\\Baker',\n                'assistant_chef' =\u003e 'App\\Model\\Entity\\AssistantChef',\n            ]\n        ]);\n\n        // Optionally, set the default type. If none is defined, the\n        // first one (i.e. `chef`) will be used.\n        $this-\u003esetEntityClass('App\\Model\\Entity\\AssistantChef');\n    }\n}\n```\n\nThen create a class for every type of entity:\n\n- Chef\n- Baker\n- AssistantChef\n\nThe entity that was previously defined to be the 'default' one will need to use the `StiAwareTrait`:\n\n```php\n\u003c?php // src/Model/Entity/AssistantChef.php\nnamespace App\\Model\\Entity;\n\nuse Cake\\ORM\\Entity;\nuse Muffin\\Sti\\Model\\Entity\\StiAwareTrait;\n\nclass AssistantChef extends Entity\n{\n    use StiAwareTrait;\n}\n```\n\nOptionally, you can create classes for your tables that extend the parent table to encapsulate business logic:\n\n```php\n\u003c?php // src/Model/Table/ChefsTable.php\nnamespace App\\Model\\Table;\n\nclass ChefsTable extends CooksTable\n{\n  // ...\n}\n```\n\nI said optionally, because if the only thing you need is some extra validation rules, you could define those\non the parent table. For example, to add custom rules to chefs:\n\n```php\n// src/Model/Table/CooksTable.php\npublic function validationChefs(Validator $validator)\n{\n    // ...\n    return $validator;\n}\n```\n\n### New entities\n\n The behavior will automatically add helper methods for creating entities of different types\n (i.e. `newChef()`). There are different ways of creating new entities, all are valid and depending\n on the cases, you might need one or the other:\n\n ```php\n // using the parent table\n $cooks-\u003enewChef([...]);\n\n // or, using the parent table again\n $cooks-\u003enewEntity(['type' =\u003e 'chef', ...]);\n\n // or, using the child table\n $chefs-\u003enewEntity([...]);\n ```\n\n### Note\n\nFor the above examples to work using (*chef), you need to add a custom rule to the `Inflector`:\n\n```php\nCake\\Utility\\Inflector::rules('plural', ['/chef$/i' =\u003e '\\1Chefs']);\n```\n\n## Patches \u0026 Features\n\n* Fork\n* Mod, fix\n* Test - this is important, so it's not unintentionally broken\n* Commit - do not mess with license, todo, version, etc. (if you do change any, bump them into commits of\ntheir own that I can ignore when I pull)\n* Pull request - bonus point for topic branches\n\nTo ensure your PRs are considered for upstream, you MUST follow the [CakePHP coding standards][standards].\n\n## Bugs \u0026 Feedback\n\nhttp://github.com/usemuffin/sti/issues\n\n## License\n\nCopyright (c) 2015-Present, [Use Muffin][muffin] and licensed under [The MIT License][mit].\n\n[cakephp]:http://cakephp.org\n[composer]:http://getcomposer.org\n[mit]:http://www.opensource.org/licenses/mit-license.php\n[muffin]:http://usemuffin.com\n[standards]:http://book.cakephp.org/3.0/en/contributing/cakephp-coding-conventions.html\n[1]:https://en.wikipedia.org/wiki/Single_Table_Inheritance\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FUseMuffin%2FSti","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FUseMuffin%2FSti","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FUseMuffin%2FSti/lists"}