{"id":13684426,"url":"https://github.com/usemuffin/trash","last_synced_at":"2025-12-28T10:45:46.635Z","repository":{"id":35171070,"uuid":"39428165","full_name":"UseMuffin/Trash","owner":"UseMuffin","description":"Adds soft-delete support to CakePHP ORM.","archived":false,"fork":false,"pushed_at":"2025-02-04T07:20:01.000Z","size":154,"stargazers_count":85,"open_issues_count":6,"forks_count":36,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-23T00:37:10.443Z","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,"publiccode":null,"codemeta":null}},"created_at":"2015-07-21T06:28:36.000Z","updated_at":"2025-02-04T07:09:18.000Z","dependencies_parsed_at":"2022-06-27T13:31:55.520Z","dependency_job_id":"23255569-b8b9-4d14-8ae1-2b7012c87057","html_url":"https://github.com/UseMuffin/Trash","commit_stats":{"total_commits":113,"total_committers":20,"mean_commits":5.65,"dds":0.6017699115044248,"last_synced_commit":"e540acfbb5838ae174264b95b8b0469c03bb99e8"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UseMuffin%2FTrash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UseMuffin%2FTrash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UseMuffin%2FTrash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UseMuffin%2FTrash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/UseMuffin","download_url":"https://codeload.github.com/UseMuffin/Trash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251777780,"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.393Z","updated_at":"2025-12-28T10:45:46.574Z","avatar_url":"https://github.com/UseMuffin.png","language":"PHP","funding_links":[],"categories":["ORM / Database / Datamapping","Plugins"],"sub_categories":["ORM / Database / Datamapping"],"readme":"# Trash\n\n[![Build Status](https://img.shields.io/github/actions/workflow/status/UseMuffin/Trash/ci.yml?style=flat-square\n)](https://github.com/UseMuffin/Trash/actions?query=workflow%3ACI+branch%3Amaster)\n[![Coverage](https://img.shields.io/codecov/c/github/UseMuffin/Trash/master.svg?style=flat-square)](https://codecov.io/github/UseMuffin/Trash)\n[![Total Downloads](https://img.shields.io/packagist/dt/muffin/trash.svg?style=flat-square)](https://packagist.org/packages/muffin/trash)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE)\n\nAdds \"soft\"-delete support to CakePHP tables.\n\n## Install\n\nUsing [Composer][composer]:\n\n```\ncomposer require muffin/trash\n```\n\nYou then need to load the plugin. You can use the shell command:\n\n```\nbin/cake plugin load Muffin/Trash\n```\n\n## Usage\n\nIn your table(s), add the behavior like you would for any other behavior:\n\n```php\n// in the initialize() method\n$this-\u003eaddBehavior('Muffin/Trash.Trash');\n```\n\nBy default, the behavior expects your table to have a *nullable* `DATETIME` column\nnamed `deleted` or `trashed`. Or you could customize the name when adding the behavior:\n\n```php\n// in your table's initialize() method\n$this-\u003eaddBehavior('Muffin/Trash.Trash', [\n    'field' =\u003e 'deleted_at'\n]);\n```\n\nor, at the global level, in `bootstrap.php`:\n\n```php\nConfigure::write('Muffin/Trash.field', 'deleted_at');\n```\n\nFinally, if you would like to keep the default cake behavior when running\n`find()` or `delete()` operations and explicitly call the behavior when you need\n'trash'-ing functionality, just disable the event(s):\n\n```php\n// in the initialize() method\n$this-\u003eaddBehavior('Muffin/Trash.Trash', [\n    'events' =\u003e ['Model.beforeFind'] // enables the beforeFind event only, false to disable both\n]);\n```\n\nor use the purge option:\n\n```php\n$table-\u003edelete($entity, ['purge' =\u003e true]);\n```\n\n## Detecting trashing\nIf you need to distinguish between deletion and trashing the behavior\nadds the ['trash' =\u003e true ] option to the afterDelete event\nit creates when trashing.\n\n### Cascading deletion\n\nIf you'd like to have related records marked as trashed when deleting a parent\nitem, you can just attach the behavior to the related table classes, and set the\n`'dependent' =\u003e true, 'cascadeCallbacks' =\u003e true` options in the table relationships.\n\nThis works on relationships where the item being deleted in the owning side of\nthe relationship. Which means that the related table should contain the foreign key.\n\nIf you don't want to cascade on trash:\n```php\n// in the initialize() method\n$this-\u003eaddBehavior('Muffin/Trash.Trash', [\n    'cascadeOnTrash' =\u003e false,\n]);\n```\n\n### Custom Finders\n\n- **onlyTrashed** - helps getting only those trashed records.\n- **withTrashed** - when filtering out the trashed records by default, this method comes in handy to have them included\nas part of certain calls.\n\n### Extras\n\n- **emptyTrash()** - permanently deletes all trashed records.\n- **restoreTrash($entity = null, array $options = [])** - restores one (or all) trashed records.\n- **cascadingRestoreTrash($entity = null, array $options = [])** - restores one (or all) trashed records including\nthose of dependent associations.\n- **trash($entity, array $options = [])** - like `delete()` but for a soft-delete (handy when `Model.beforeDelete` is\ndisabled by default).\n- **trashAll(array $conditions)** - like `deleteAll()` but for soft-deletes.\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.\n\n## Bugs \u0026 Feedback\n\nhttp://github.com/usemuffin/trash/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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusemuffin%2Ftrash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fusemuffin%2Ftrash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusemuffin%2Ftrash/lists"}