{"id":28754243,"url":"https://github.com/zeroasterisk/sticky-cakephp-plugin","last_synced_at":"2025-06-17T01:08:04.409Z","repository":{"id":17334422,"uuid":"20105646","full_name":"zeroasterisk/Sticky-CakePHP-Plugin","owner":"zeroasterisk","description":"Stickyable Behavior to maintain contain and joins for multiple finds","archived":false,"fork":false,"pushed_at":"2014-09-26T20:20:28.000Z","size":156,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2023-03-11T05:08:23.016Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zeroasterisk.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-05-23T16:07:35.000Z","updated_at":"2015-04-07T17:55:37.000Z","dependencies_parsed_at":"2022-07-26T14:48:08.152Z","dependency_job_id":null,"html_url":"https://github.com/zeroasterisk/Sticky-CakePHP-Plugin","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"purl":"pkg:github/zeroasterisk/Sticky-CakePHP-Plugin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeroasterisk%2FSticky-CakePHP-Plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeroasterisk%2FSticky-CakePHP-Plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeroasterisk%2FSticky-CakePHP-Plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeroasterisk%2FSticky-CakePHP-Plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zeroasterisk","download_url":"https://codeload.github.com/zeroasterisk/Sticky-CakePHP-Plugin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeroasterisk%2FSticky-CakePHP-Plugin/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260269460,"owners_count":22983647,"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":"2025-06-17T01:08:03.632Z","updated_at":"2025-06-17T01:08:04.384Z","avatar_url":"https://github.com/zeroasterisk.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# StickyableBehavior\n\n*packaged as a CakePHP Plugin for convenience*\n\n## Install\n\nPut in place: `app/Plugin/Sticky`\n\n    git submodule add https://github.com/zeroasterisk/Sticky-CakePHP-Plugin.git app/Plugin/Sticky\n\nor\n\n    cd app/Plugin\n    git clone https://github.com/zeroasterisk/Sticky-CakePHP-Plugin.git Sticky\n\nthen add in `app/Config/bootstrap.php`\n\n    CakePlugin::load('Sticky');\n\nfinally, put this **above** Containable on any Model you want to use it on\n(or in AppModel to use on all Models)\n\n    /**\n    * behavior attachments (global)\n    */\n    public $actsAs = array(\n      'Sticky.Stickyable',\n      'Containable',\n    );\n\n## Usage: Setup 'contain' and 'joins' for 'find()'\n\nSo in this example, you could eaisly just pass in all of these details via find\n`$options`... assuming all of these methods were done in line...\n\nBut lets assume that the logic is broken up into sub-functions in a variety of\nplaces (on the model, on the controller, in a Behavior... wherever)\n\nFind out more on the [Unit\nTests](https://github.com/zeroasterisk/Sticky-CakePHP-Plugin/blob/master/Test/Case/Model/Behavior/StickyableBehaviorTest.php)\n\n    // find all Articles on which I have commented\n    //   we setup a hasOne() for MyComment (allowing a simple inner join)\n    //   we setup a Sticky Contain with conditions\n    $this-\u003eArticle-\u003erecursive = -1;\n    ... some sort of logic ...\n    // add a sticky contains\n    $this-\u003eArticle-\u003eaddStickyContain(array(\n        'MyComment' =\u003e array(\n            'fields' =\u003e array('id', 'created'),\n            'conditions' =\u003e array(\n                'MyComment.user_id' =\u003e 2\n            )\n        ),\n    ));\n    ... some sort of logic ...\n    // prep options for a find requiring the sticky contains\n    $options = array(\n        'fields' =\u003e array('id', 'title'),\n        'conditions' =\u003e array(\n            'NOT' =\u003e array(\n                'MyComment.id' =\u003e NULL\n            ),\n        ),\n    );\n    $articlesWhichIHaveCommentedOn = $this-\u003eArticle-\u003efind('all', $options),\n    // works on multiple queries\n    $articlesWhichIHaveCommentedOn = $this-\u003eArticle-\u003efind('all', $options),\n    // works on multiple queries of different types too\n    $howMany = $this-\u003eArticle-\u003efind('count', $options),\n\n## Why / Background\n\nFirst, a big shout-out to the CakeDC Search plugin:\n\n* https://github.com/CakeDC/search\n\nThat is a wonderful to keep your search filters organized and arranged into\nmanagable chunks.  It is a direct result of working with that tool which\nprompted me to write this.\n\nWhen creating a `type=query`, I wanted to be able to modify the 'contain' or 'joins'\nof the subsequent `find()` - but there was no way to do so.\n\nI could use the `$Model-\u003econtain()` but that resets all the contains, and it\nonly lasts for the \"next\" query, not all times these conditions might be used\n(pagination requires 2 finds).\n\n## Performance (Joins are better then Subqueries)\n\nAlso, while I could accomplish much of what I wanted with subqueries, sadly the\nperformance of subqueries in MySQL is poor as compared with inner joins...\n\nTherefore, setting up a \"sticky\" join becomes important...\nit allows us to search within a `hasMany` association, easily and quickly.\n\n## Attribution\n\nAs mentioned already, thanks to CakeDC for their Search plugin:\n\n* https://github.com/CakeDC/search\n\n...\n\nand of course, you... pull requests welcome!\n\n## License\n\nThis code is licensed under the MIT License\n\n\nCopyright (C) 2013--2014 Alan Blount \u003calan@zeroasterisk.com\u003e https://github.com/zeroasterisk/\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\nof the Software, and to permit persons to whom the Software is furnished to do\nso, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeroasterisk%2Fsticky-cakephp-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzeroasterisk%2Fsticky-cakephp-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeroasterisk%2Fsticky-cakephp-plugin/lists"}