{"action":"created","issue":{"url":"https://api.github.com/repos/cakephp/cakephp/issues/6643","labels_url":"https://api.github.com/repos/cakephp/cakephp/issues/6643/labels{/name}","comments_url":"https://api.github.com/repos/cakephp/cakephp/issues/6643/comments","events_url":"https://api.github.com/repos/cakephp/cakephp/issues/6643/events","html_url":"https://github.com/cakephp/cakephp/issues/6643","id":81053786,"number":6643,"title":"CakePHP 2.x: Model::saveAll() gets the associations reset before actually saving","user":{"login":"TamasBarta","id":1753591,"avatar_url":"https://avatars.githubusercontent.com/u/1753591?v=3","gravatar_id":"","url":"https://api.github.com/users/TamasBarta","html_url":"https://github.com/TamasBarta","followers_url":"https://api.github.com/users/TamasBarta/followers","following_url":"https://api.github.com/users/TamasBarta/following{/other_user}","gists_url":"https://api.github.com/users/TamasBarta/gists{/gist_id}","starred_url":"https://api.github.com/users/TamasBarta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TamasBarta/subscriptions","organizations_url":"https://api.github.com/users/TamasBarta/orgs","repos_url":"https://api.github.com/users/TamasBarta/repos","events_url":"https://api.github.com/users/TamasBarta/events{/privacy}","received_events_url":"https://api.github.com/users/TamasBarta/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/cakephp/cakephp/labels/models","name":"models","color":"FFFFFF"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/cakephp/cakephp/milestones/42","html_url":"https://github.com/cakephp/cakephp/milestones/2.6.6","labels_url":"https://api.github.com/repos/cakephp/cakephp/milestones/42/labels","id":1127751,"number":42,"title":"2.6.6","description":"Bugfixes and optimizations for the 2.6 release series.","creator":{"login":"markstory","id":24086,"avatar_url":"https://avatars.githubusercontent.com/u/24086?v=3","gravatar_id":"","url":"https://api.github.com/users/markstory","html_url":"https://github.com/markstory","followers_url":"https://api.github.com/users/markstory/followers","following_url":"https://api.github.com/users/markstory/following{/other_user}","gists_url":"https://api.github.com/users/markstory/gists{/gist_id}","starred_url":"https://api.github.com/users/markstory/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/markstory/subscriptions","organizations_url":"https://api.github.com/users/markstory/orgs","repos_url":"https://api.github.com/users/markstory/repos","events_url":"https://api.github.com/users/markstory/events{/privacy}","received_events_url":"https://api.github.com/users/markstory/received_events","type":"User","site_admin":false},"open_issues":15,"closed_issues":6,"state":"open","created_at":"2015-05-25T00:56:35Z","updated_at":"2015-05-27T07:20:59Z","due_on":"2015-06-21T04:00:00Z","closed_at":null},"comments":2,"created_at":"2015-05-26T17:12:14Z","updated_at":"2015-05-27T08:59:06Z","closed_at":"2015-05-27T00:19:25Z","body":"When I create a model, and call `unbindModel` on it, and just after it a `saveAll`, I get MySQL errors telling me that the ON clause is erroneous, containing fields that are not present (of course not present, that's why I want to unbind the related model).\r\n\r\nI started to dig in the `Model` class, and found that in the validation process some `exists` checks are running, and that translates in our project to `SoftDeleteBehavior::existsAndNotDeleted` which runs a `find`, that somewhere calls `Model::resetAssociations`. Wow. That just ruins the whole purpose of running `unbindModel` before `saveAll`. I might be missing something, but now I have to manually unset associations from `Model::belongsTo` the PHP way, so that doesn't get into a temporary container that later even before the first call resets `belongsTo`.\r\n\r\nI think this is a bug, but since now I saw so many so strange things in CakePHP, I just don't really know how it should work, or how it should be used."},"comment":{"url":"https://api.github.com/repos/cakephp/cakephp/issues/comments/105829887","html_url":"https://github.com/cakephp/cakephp/issues/6643#issuecomment-105829887","issue_url":"https://api.github.com/repos/cakephp/cakephp/issues/6643","id":105829887,"user":{"login":"TamasBarta","id":1753591,"avatar_url":"https://avatars.githubusercontent.com/u/1753591?v=3","gravatar_id":"","url":"https://api.github.com/users/TamasBarta","html_url":"https://github.com/TamasBarta","followers_url":"https://api.github.com/users/TamasBarta/followers","following_url":"https://api.github.com/users/TamasBarta/following{/other_user}","gists_url":"https://api.github.com/users/TamasBarta/gists{/gist_id}","starred_url":"https://api.github.com/users/TamasBarta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TamasBarta/subscriptions","organizations_url":"https://api.github.com/users/TamasBarta/orgs","repos_url":"https://api.github.com/users/TamasBarta/repos","events_url":"https://api.github.com/users/TamasBarta/events{/privacy}","received_events_url":"https://api.github.com/users/TamasBarta/received_events","type":"User","site_admin":false},"created_at":"2015-05-27T08:59:06Z","updated_at":"2015-05-27T08:59:06Z","body":"I also saw that there won't be an easy way, but at least mentioning it in the documentation would be nice. (I'm sure the second parameter of unbind is documented, I mean the strange behaviour)\r\nI've been googling and debugging for hours to solve this mystery.\r\nAt least now this issue might be found if someone has the same issue, and your answer gives a decent workaround, but I don't understand your intentions you declared by closing this issue.\r\nThanks for your fast response though, I appreciate it."}}