{"id":15296174,"url":"https://github.com/zunderbolt/cakephp-softdelete-trait","last_synced_at":"2025-07-05T01:33:23.195Z","repository":{"id":24114690,"uuid":"27502875","full_name":"zunderbolt/cakephp-softdelete-trait","owner":"zunderbolt","description":"CakePHP Soft Delete Trait","archived":false,"fork":false,"pushed_at":"2014-12-03T19:19:43.000Z","size":124,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T10:13:41.690Z","etag":null,"topics":["cakephp","cakephp2","model","php","softdelete","trait"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zunderbolt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-12-03T19:06:53.000Z","updated_at":"2024-02-04T11:45:18.000Z","dependencies_parsed_at":"2022-08-22T09:50:30.642Z","dependency_job_id":null,"html_url":"https://github.com/zunderbolt/cakephp-softdelete-trait","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zunderbolt%2Fcakephp-softdelete-trait","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zunderbolt%2Fcakephp-softdelete-trait/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zunderbolt%2Fcakephp-softdelete-trait/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zunderbolt%2Fcakephp-softdelete-trait/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zunderbolt","download_url":"https://codeload.github.com/zunderbolt/cakephp-softdelete-trait/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248768522,"owners_count":21158654,"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":["cakephp","cakephp2","model","php","softdelete","trait"],"created_at":"2024-09-30T18:09:39.137Z","updated_at":"2025-04-13T19:35:26.503Z","avatar_url":"https://github.com/zunderbolt.png","language":"PHP","readme":"# CakePHP Soft Delete Trait\n\nSoft delete trait for using with CakePHP 2.x models. \n\nSometimes it is useful to flag records as deleted instead of physically removing them from the database. Achieving that with this plugin requires no custom delete method calls or custom find conditions to exclude deleted records - your models delete() and find()/read() will just work.  It is also possible to fetch deleted records when needed or perform \"hard\" delete.\n\n## Requirements\n\n* CakePHP 2.x\n* PHP 5.4+\n\n## Installation\n\n### With Composer\n\n\n```\n\"require\": {\n    \"zunderbolt/cakephp-softdelete-trait\": \"dev-master\"\n}\n```\n\n### Manual\n\n* Download files to `APP/Plugin/SoftDeleteTrait`\n\n## Configuration\n\n* Load plugin with `CakePlugin::load('SoftDeleteTrait');` in `bootstrap.php` or where needed.\n* Show the app where to look for source file `App::uses('SoftDeleteTrait', 'SoftDeleteTrait.Lib');` or load it with your autoloader.\n* Use the trait in your model and implement method `_deletedFieldName`, which should return the name of database field for deletion tracking.\n* Don't forget to add the field in your database table. It can be boolean flag (TINYINT/INT field, 1 for deleted record, 0 otherwise), date or datetime (NULL for normal record, date/datetime of removal for deleted record).\n\nExample:\n```php\n    App::uses('SoftDeleteTrait', 'SoftDeleteTrait.Lib');\n\n    class Item extends AppModel {\n        use SoftDeleteTrait;\n        \n        protected function _deletedFieldName() {\n            return 'isDeleted';\n        }\n```\n\n## Usage notes\n\nSoft delete and exclusion of deleted records from find/read results works automagically.\nTo include deleted records in find results use $this-\u003eincludeDeletedRecords() in your model. To exclude them again use the excludeDeletedRecords() method.\n\nTo save some additional data for deleted records you can implement protected method _additionalFieldsForDeletedRecord() in your model. For example, you can set record's status and removal reason:\n```php\n    protected function _additionalFieldsForDeletedRecord() {\n        return [\n            'removalReason' =\u003e 'Useless stuff',\n            'status'        =\u003e self::STATUS_DELETED\n        ];\n    }\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzunderbolt%2Fcakephp-softdelete-trait","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzunderbolt%2Fcakephp-softdelete-trait","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzunderbolt%2Fcakephp-softdelete-trait/lists"}