{"action":"created","issue":{"url":"https://api.github.com/repos/cakephp/cakephp/issues/6315","labels_url":"https://api.github.com/repos/cakephp/cakephp/issues/6315/labels{/name}","comments_url":"https://api.github.com/repos/cakephp/cakephp/issues/6315/comments","events_url":"https://api.github.com/repos/cakephp/cakephp/issues/6315/events","html_url":"https://github.com/cakephp/cakephp/issues/6315","id":67650496,"number":6315,"title":"Again, BTM _joinTable id problem","user":{"login":"Tzaoh","id":5722357,"avatar_url":"https://avatars.githubusercontent.com/u/5722357?v=3","gravatar_id":"","url":"https://api.github.com/users/Tzaoh","html_url":"https://github.com/Tzaoh","followers_url":"https://api.github.com/users/Tzaoh/followers","following_url":"https://api.github.com/users/Tzaoh/following{/other_user}","gists_url":"https://api.github.com/users/Tzaoh/gists{/gist_id}","starred_url":"https://api.github.com/users/Tzaoh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tzaoh/subscriptions","organizations_url":"https://api.github.com/users/Tzaoh/orgs","repos_url":"https://api.github.com/users/Tzaoh/repos","events_url":"https://api.github.com/users/Tzaoh/events{/privacy}","received_events_url":"https://api.github.com/users/Tzaoh/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/cakephp/cakephp/labels/On%20hold","name":"On hold","color":"eb6420"},{"url":"https://api.github.com/repos/cakephp/cakephp/labels/ORM","name":"ORM","color":"ffffff"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/cakephp/cakephp/milestones/41","html_url":"https://github.com/cakephp/cakephp/milestones/3.0.6","labels_url":"https://api.github.com/repos/cakephp/cakephp/milestones/41/labels","id":1114477,"number":41,"title":"3.0.6","description":"Bugfixes, optimizations and minor enhancements for 3.0.x","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":9,"closed_issues":56,"state":"closed","created_at":"2015-05-18T01:40:12Z","updated_at":"2015-06-17T01:33:05Z","due_on":"2015-05-31T04:00:00Z","closed_at":"2015-05-28T15:26:56Z"},"comments":24,"created_at":"2015-04-10T18:06:50Z","updated_at":"2015-09-21T02:27:28Z","closed_at":null,"body":"Well I am trying to save a belongsToMany relation between two tables, specifying the primaryKeys in the data I want to save for both models: source and target.\r\nThe two foreignKey of the \"middle\" table are the composite primaryKey too. So no autonumeric primaryKey.\r\n\r\nBut it does not save anything apart of the source model. This is because in``\\vendor\\cakephp\\cakephp\\src\\ORM\\Marshaller.php`` it is assuming that if the primaryKey in the target model is specified, the entity already exists in the table.\r\n```php\r\n// Accept [ [id => 1], [id = 2] ] style.\r\n        $primaryKey = array_flip($assoc->target()->schema()->primaryKey());\r\n        if (array_intersect_key($primaryKey, current($data)) === $primaryKey) {\r\n            $primaryCount = count($primaryKey);\r\n            $query = $assoc->find();\r\n            foreach ($data as $row) {\r\n                $keys = array_intersect_key($row, $primaryKey);\r\n                if (count($keys) === $primaryCount) {\r\n                    $query->orWhere($keys);\r\n                }\r\n            }\r\n            $records = $query->toArray();\r\n        } else {\r\n            $records = $this->many($data, $options);\r\n        }\r\n```\r\n\r\nI could imagine a possible solution would be to add an autonumeric primary key to the middle table and set the currently composite primaryKey to be only foreignKeys, but I prefer to not create an extra field here.\r\n\r\nI tried the version of the file 3.0.0-RC1 and it works because the code commented above was included later. Is possible to have this in mind?"},"comment":{"url":"https://api.github.com/repos/cakephp/cakephp/issues/comments/141861727","html_url":"https://github.com/cakephp/cakephp/issues/6315#issuecomment-141861727","issue_url":"https://api.github.com/repos/cakephp/cakephp/issues/6315","id":141861727,"user":{"login":"mylux","id":11030522,"avatar_url":"https://avatars.githubusercontent.com/u/11030522?v=3","gravatar_id":"","url":"https://api.github.com/users/mylux","html_url":"https://github.com/mylux","followers_url":"https://api.github.com/users/mylux/followers","following_url":"https://api.github.com/users/mylux/following{/other_user}","gists_url":"https://api.github.com/users/mylux/gists{/gist_id}","starred_url":"https://api.github.com/users/mylux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mylux/subscriptions","organizations_url":"https://api.github.com/users/mylux/orgs","repos_url":"https://api.github.com/users/mylux/repos","events_url":"https://api.github.com/users/mylux/events{/privacy}","received_events_url":"https://api.github.com/users/mylux/received_events","type":"User","site_admin":false},"created_at":"2015-09-21T02:27:28Z","updated_at":"2015-09-21T02:27:28Z","body":"Ah, OK. That's why I've got a bit lost. Thanks @markstory\r\nAbout this subject (non unique columns) I don't have a good feeling about this. If the Marshaller becomes so \"smart\", the possibility of unexpected behavior increases. And its maintenance can become really painful."}}