{"action":"created","issue":{"url":"https://api.github.com/repos/cakephp/cakephp/issues/8264","repository_url":"https://api.github.com/repos/cakephp/cakephp","labels_url":"https://api.github.com/repos/cakephp/cakephp/issues/8264/labels{/name}","comments_url":"https://api.github.com/repos/cakephp/cakephp/issues/8264/comments","events_url":"https://api.github.com/repos/cakephp/cakephp/issues/8264/events","html_url":"https://github.com/cakephp/cakephp/issues/8264","id":133821200,"number":8264,"title":"Tree behavior doesn't calculate lft/rght correctly on creation","user":{"login":"sdustinh","id":2855100,"avatar_url":"https://avatars.githubusercontent.com/u/2855100?v=3","gravatar_id":"","url":"https://api.github.com/users/sdustinh","html_url":"https://github.com/sdustinh","followers_url":"https://api.github.com/users/sdustinh/followers","following_url":"https://api.github.com/users/sdustinh/following{/other_user}","gists_url":"https://api.github.com/users/sdustinh/gists{/gist_id}","starred_url":"https://api.github.com/users/sdustinh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sdustinh/subscriptions","organizations_url":"https://api.github.com/users/sdustinh/orgs","repos_url":"https://api.github.com/users/sdustinh/repos","events_url":"https://api.github.com/users/sdustinh/events{/privacy}","received_events_url":"https://api.github.com/users/sdustinh/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/cakephp/cakephp/labels/behaviors","name":"behaviors","color":"FFFFFF"},{"url":"https://api.github.com/repos/cakephp/cakephp/labels/Defect","name":"Defect","color":"f7c6c7"},{"url":"https://api.github.com/repos/cakephp/cakephp/labels/ORM","name":"ORM","color":"ffffff"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/cakephp/cakephp/milestones/79","html_url":"https://github.com/cakephp/cakephp/milestones/3.2.3","labels_url":"https://api.github.com/repos/cakephp/cakephp/milestones/79/labels","id":1579024,"number":79,"title":"3.2.3","description":"Bugfixes and minor enhancements for 3.2.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":32,"closed_issues":27,"state":"open","created_at":"2016-02-12T03:23:02Z","updated_at":"2016-02-15T22:44:51Z","due_on":"2016-02-28T05:00:00Z","closed_at":null},"comments":2,"created_at":"2016-02-15T21:27:14Z","updated_at":"2016-02-15T22:44:51Z","closed_at":"2016-02-15T22:44:51Z","body":"All of this is done with classes generated by `bake`. I thought may be it was something I had configured incorrectly but I have been able to replicate it with straight generated classes as well. Here is the setup...\r\n\r\n```sql\r\nCREATE TABLE IF NOT EXISTS `device_type_groups` (\r\n  `id` int(11) NOT NULL AUTO_INCREMENT,\r\n  `parent_id` int(11) DEFAULT NULL,\r\n  `lft` int(11) DEFAULT NULL,\r\n  `rght` int(11) DEFAULT NULL,\r\n  `created` datetime DEFAULT NULL,\r\n  `modified` datetime DEFAULT NULL,\r\n  `name` varchar(255) NOT NULL,\r\n  PRIMARY KEY (`id`),\r\n  KEY `parent_id` (`parent_id`,`lft`,`rght`)\r\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;\r\n```\r\n\r\n```php\r\n// DeviceTypeGroupsTable.php\r\npublic function initialize(array $config)\r\n{\r\n    parent::initialize($config);\r\n    \r\n    $this->table('device_type_groups');\r\n    $this->displayField('name');\r\n    $this->primaryKey('id');\r\n    \r\n    $this->addBehavior('Timestamp');\r\n    $this->addBehavior('Tree');\r\n    \r\n    $this->hasMany('ChildGroups', [\r\n        'className' => 'DeviceTypeGroups',\r\n        'dependent' => true,\r\n        'foreignKey' => 'parent_id'\r\n    ]);\r\n    $this->belongsTo('ParentGroups', [\r\n        'className' => 'DeviceTypeGroups',\r\n        'foreignKey' => 'parent_id'\r\n    ]);\r\n}\r\n```\r\n\r\n```php\r\n// Adding data...\r\n$groups = [\r\n    ['name' => 'Environmental'],\r\n    ['name' => 'Network'],\r\n    ['name' => 'Power'],\r\n    ['name' => 'Server'],\r\n    [\r\n        'name' => 'Switch',\r\n        'child_groups' => [\r\n            ['name' => 'Access'],\r\n            ['name' => 'Core'],\r\n            ['name' => 'Layer 3'],\r\n        ]\r\n    ],\r\n    ['name' => 'Uplink']\r\n];\r\n\r\nforeach ($groups as $data) {\r\n    $entity = $this->DeviceTypeGroups->newEntity($data);\r\n    $this->DeviceTypeGroups->save($entity);\r\n}\r\n```\r\n\r\n```sql\r\n// Resulting records...\r\nINSERT INTO `device_type_groups` (`id`, `parent_id`, `lft`, `rght`, `created`, `modified`, `name`) VALUES\r\n(1, NULL, 1, 2, '2016-02-15 21:17:59', '2016-02-15 21:17:59', 'Environmental'),\r\n(2, NULL, 3, 4, '2016-02-15 21:17:59', '2016-02-15 21:17:59', 'Network'),\r\n(3, NULL, 5, 6, '2016-02-15 21:17:59', '2016-02-15 21:17:59', 'Power'),\r\n(4, NULL, 7, 8, '2016-02-15 21:17:59', '2016-02-15 21:17:59', 'Server'),\r\n(5, NULL, 9, 16, '2016-02-15 21:17:59', '2016-02-15 21:17:59', 'Switch'),\r\n(6, 5, 10, 11, '2016-02-15 21:17:59', '2016-02-15 21:17:59', 'Access'),\r\n(7, 5, 12, 13, '2016-02-15 21:17:59', '2016-02-15 21:17:59', 'Core'),\r\n(8, 5, 14, 15, '2016-02-15 21:17:59', '2016-02-15 21:17:59', 'Layer 3'),\r\n(9, NULL, 16, 17, '2016-02-15 21:17:59', '2016-02-15 21:17:59', 'Uplink');\r\n```\r\n\r\nThere is a key overlap with the \"Switch\" and \"Uplink\"  records. I have also tried to fix this by using a transaction but it does the same thing. Running `recover()` does fix it.\r\n\r\nCakePHP: 3.2.1\r\nMySQL: 5.6.28\r\nPHP: 5.6.18\r\nOS: Ubuntu 14.04"},"comment":{"url":"https://api.github.com/repos/cakephp/cakephp/issues/comments/184427507","html_url":"https://github.com/cakephp/cakephp/issues/8264#issuecomment-184427507","issue_url":"https://api.github.com/repos/cakephp/cakephp/issues/8264","id":184427507,"user":{"login":"sdustinh","id":2855100,"avatar_url":"https://avatars.githubusercontent.com/u/2855100?v=3","gravatar_id":"","url":"https://api.github.com/users/sdustinh","html_url":"https://github.com/sdustinh","followers_url":"https://api.github.com/users/sdustinh/followers","following_url":"https://api.github.com/users/sdustinh/following{/other_user}","gists_url":"https://api.github.com/users/sdustinh/gists{/gist_id}","starred_url":"https://api.github.com/users/sdustinh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sdustinh/subscriptions","organizations_url":"https://api.github.com/users/sdustinh/orgs","repos_url":"https://api.github.com/users/sdustinh/repos","events_url":"https://api.github.com/users/sdustinh/events{/privacy}","received_events_url":"https://api.github.com/users/sdustinh/received_events","type":"User","site_admin":false},"created_at":"2016-02-15T22:44:51Z","updated_at":"2016-02-15T22:44:51Z","body":"It looks like this was fixed in #8245 and I just didn't find an issue for it. I pulled down 08e43f7cb8cd4ea37bf380da6b704c206fead6f0 to test it out and it seems to be fixed. Sorry for not pulling master first. I guess I just wasn't even paying attention. :smirk: "}}