{"action":"created","issue":{"url":"https://api.github.com/repos/overlookmotel/sequelize-hierarchy/issues/65","repository_url":"https://api.github.com/repos/overlookmotel/sequelize-hierarchy","labels_url":"https://api.github.com/repos/overlookmotel/sequelize-hierarchy/issues/65/labels{/name}","comments_url":"https://api.github.com/repos/overlookmotel/sequelize-hierarchy/issues/65/comments","events_url":"https://api.github.com/repos/overlookmotel/sequelize-hierarchy/issues/65/events","html_url":"https://github.com/overlookmotel/sequelize-hierarchy/issues/65","id":162282295,"number":65,"title":"SequelizeUniqueConstraintError on child creation","user":{"login":"Varkal","id":3471491,"avatar_url":"https://avatars.githubusercontent.com/u/3471491?v=3","gravatar_id":"","url":"https://api.github.com/users/Varkal","html_url":"https://github.com/Varkal","followers_url":"https://api.github.com/users/Varkal/followers","following_url":"https://api.github.com/users/Varkal/following{/other_user}","gists_url":"https://api.github.com/users/Varkal/gists{/gist_id}","starred_url":"https://api.github.com/users/Varkal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Varkal/subscriptions","organizations_url":"https://api.github.com/users/Varkal/orgs","repos_url":"https://api.github.com/users/Varkal/repos","events_url":"https://api.github.com/users/Varkal/events{/privacy}","received_events_url":"https://api.github.com/users/Varkal/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-06-25T13:57:28Z","updated_at":"2016-06-25T14:36:48Z","closed_at":null,"body":"This simple test throw a SequelizeUniqueConstraintError\r\n\r\n```\r\nbeforeEach((done) => {\r\n            models.sequelize.sync({force: true}).then(() => {\r\n                this.Account = models.Account;\r\n                done();\r\n            });\r\n});\r\n\r\nit('shoud handle correctly hierarchy of account', () => {\r\n            var parentAccount = {\r\n                title  : \"Parent Account\",\r\n                balance: 0\r\n            };\r\n\r\n            var childAccount = {\r\n                title  : \"Child Account\",\r\n                balance: 0\r\n            };\r\n\r\n            return this.Account.create(parentAccount)\r\n                .then((parentAccountCreated) => {\r\n                    childAccount.parentId = parentAccountCreated.id;\r\n                    return this.Account.create(childAccount)\r\n                })\r\n                .then(\r\n                    (childAccountCreated) => {\r\n                        console.log(childAccountCreated.parentId);\r\n                    },\r\n                    (error) => {\r\n                        console.log(error);\r\n                    }\r\n                )\r\n        });\r\n```\r\nBut, after exec it, in MySQL i dound those datas : \r\n\r\n| id | title          | balance | deleted | deletion_date | creation_date       | modification_date   | hierarchyLevel | parentId |\r\n+----+----------------+---------+---------+---------------+---------------------+---------------------+-------------+\r\n|  1 | Parent Account |       0 |    NULL | NULL          | 2016-06-25 13:51:35 | 2016-06-25 13:51:35 |              1 |     NULL |\r\n|  2 | Child Account  |       0 |    NULL | NULL          | 2016-06-25 13:51:35 | 2016-06-25 13:51:35 |              2 |        1 |\r\n\r\nLike everything is ok.\r\n\r\nSo i don't understand where is my mistake...\r\n\r\nDo you have any idea ? \r\n\r\nSome additional infos : \r\n\r\nThe detailed error : \r\n```\r\n{ [SequelizeUniqueConstraintError: Validation error]\r\n  name: 'SequelizeUniqueConstraintError',\r\n  message: 'Validation error',\r\n  errors:\r\n   [ { message: 'PRIMARY must be unique',\r\n       type: 'unique violation',\r\n       path: 'PRIMARY',\r\n       value: '2-1' } ],\r\n  fields: { PRIMARY: '2-1' } }\r\n```\r\nThe correspondig model : \r\n```\r\nvar Account = db.define(\"Account\", {\r\n            title        : {\r\n                type: Sequelize.STRING\r\n            },\r\n            balance      : {\r\n                type: Sequelize.FLOAT\r\n            },\r\n            deleted      : {\r\n                type: Sequelize.BOOLEAN,\r\n            },\r\n            deletion_date: {\r\n                type: Sequelize.DATE\r\n            }\r\n        },\r\n        {\r\n            timestamps  : true,\r\n            createdAt   : \"creation_date\",\r\n            updatedAt   : \"modification_date\",\r\n            hierarchy   : true\r\n        });\r\n\r\n    return Account;\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/overlookmotel/sequelize-hierarchy/issues/comments/228546583","html_url":"https://github.com/overlookmotel/sequelize-hierarchy/issues/65#issuecomment-228546583","issue_url":"https://api.github.com/repos/overlookmotel/sequelize-hierarchy/issues/65","id":228546583,"user":{"login":"overlookmotel","id":557937,"avatar_url":"https://avatars.githubusercontent.com/u/557937?v=3","gravatar_id":"","url":"https://api.github.com/users/overlookmotel","html_url":"https://github.com/overlookmotel","followers_url":"https://api.github.com/users/overlookmotel/followers","following_url":"https://api.github.com/users/overlookmotel/following{/other_user}","gists_url":"https://api.github.com/users/overlookmotel/gists{/gist_id}","starred_url":"https://api.github.com/users/overlookmotel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/overlookmotel/subscriptions","organizations_url":"https://api.github.com/users/overlookmotel/orgs","repos_url":"https://api.github.com/users/overlookmotel/repos","events_url":"https://api.github.com/users/overlookmotel/events{/privacy}","received_events_url":"https://api.github.com/users/overlookmotel/received_events","type":"User","site_admin":false},"created_at":"2016-06-25T14:36:48Z","updated_at":"2016-06-25T14:36:48Z","body":"Thanks for raising this.\r\n\r\nWhen you set a hierarchy on a model, it also defines another model to track the descendents of all nodes. In your case this would be called `AccountHierarchy`.\r\n\r\nIt looks like the error is coming from trying to insert a duplicated row into `AccountHierarchy` table.\r\n\r\nTwo possibilities for why this is happening:\r\n\r\n1. A bug in this module\r\n2. `AccountHierarchy` table is not being cleared before the test run so row inserted in a previous test or previous run of this test are still present.\r\n\r\nI suspect it's (2) as there are already tests for this which are passing fine.\r\n\r\nTo narrow this down, I'd suggest the following:\r\n\r\n* Before running that test, manually delete or empty the `AccountHierarchy` table from the database, and see if you still get the same error.\r\n* Ensure that `models.sequelize.sync({force: true})` is syncing *all* models, including `AccountHierarchy`. From your code, I can't tell whether `models.sequelize` refers to the the `db` object that `Account` model is being defined on.\r\n\r\nPlease can you try this and let me know? If there's a bug, of course I want to fix it ASAP, but I *suspect* the fault is with your code somewhere."}}
{"actor":{"display_login":"overlookmotel"}}