{"action":"created","issue":{"url":"https://api.github.com/repos/bredikhin/barrels/issues/44","repository_url":"https://api.github.com/repos/bredikhin/barrels","labels_url":"https://api.github.com/repos/bredikhin/barrels/issues/44/labels{/name}","comments_url":"https://api.github.com/repos/bredikhin/barrels/issues/44/comments","events_url":"https://api.github.com/repos/bredikhin/barrels/issues/44/events","html_url":"https://github.com/bredikhin/barrels/issues/44","id":132470772,"number":44,"title":"Many to Many relations no longer working","user":{"login":"Dalanie","id":3457885,"avatar_url":"https://avatars.githubusercontent.com/u/3457885?v=3","gravatar_id":"","url":"https://api.github.com/users/Dalanie","html_url":"https://github.com/Dalanie","followers_url":"https://api.github.com/users/Dalanie/followers","following_url":"https://api.github.com/users/Dalanie/following{/other_user}","gists_url":"https://api.github.com/users/Dalanie/gists{/gist_id}","starred_url":"https://api.github.com/users/Dalanie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Dalanie/subscriptions","organizations_url":"https://api.github.com/users/Dalanie/orgs","repos_url":"https://api.github.com/users/Dalanie/repos","events_url":"https://api.github.com/users/Dalanie/events{/privacy}","received_events_url":"https://api.github.com/users/Dalanie/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2016-02-09T16:49:28Z","updated_at":"2016-06-15T20:09:39Z","closed_at":null,"body":"After updating all libraries, it seems like the many to many relations are no longer working for me. Do you happen to know if any lib-update might effect barrels?\r\n\r\nThese are my dependencies:\r\n```\r\n\r\n  \"dependencies\": {\r\n    \"async\": \"1.5.2\",\r\n    \"barrels\": \"1.6.4\",\r\n    \"bcryptjs\": \"2.3.0\",\r\n    \"bluebird\": \"3.2.2\",\r\n    \"include-all\": \"0.1.6\",\r\n    \"jsonwebtoken\": \"5.5.4\",\r\n    \"lodash\": \"4.3.0\",\r\n    \"moment-timezone\": \"0.5.0\",\r\n    \"passport\": \"0.3.2\",\r\n    \"passport-facebook\": \"2.1.0\",\r\n    \"passport-github\": \"1.1.0\",\r\n    \"passport-google\": \"0.3.0\",\r\n    \"passport-local\": \"1.0.0\",\r\n    \"passport-twitter\": \"1.0.4\",\r\n    \"passport-custom\": \"1.0.5\",\r\n    \"rc\": \"1.1.6\",\r\n    \"sails\": \"0.12.0\",\r\n    \"sails-disk\": \"0.10.9\",\r\n    \"sails-hook-apianalytics\": \"0.3.0\",\r\n    \"sails-mysql\": \"0.11.4\",\r\n    \"sails-fixtures\": \"1.0.8\",\r\n    \"ua-parser\": \"0.3.5\",\r\n    \"validator\": \"4.7.1\",\r\n    \"request\": \"2.69.0\",\r\n    \"request-promise\": \"2.0.0\",\r\n    \"winston\": \"^2.1.1\",\r\n    \"q\": \"1.4.1\"\r\n  }\r\n```\r\n\r\nI populate all models before my 'main'-model is populated. This 'main'-model contains all references to the other models, e.g:\r\n\r\n`  {\r\n    \"id\": 1,\r\n    \"title\": \"13In est risus, auctor sed,\",\r\n    \"clearance\": 1,\r\n    \"project\": 13,\r\n    \"ipType\": 0,\r\n    \"createdUser\": 12,\r\n    \"authors\": [\r\n      10,\r\n      6\r\n    ],\r\n    \"published\": \"1997-01-25\",\r\n    \"type\": 5,\r\n    \"files\": 627,\r\n    \"released\": false\r\n  },`\r\n\r\nMy other json files (such as Project, Clearance, ...) do not contain any information about this 'main' model. I did not need it before the update.\r\n\r\nOne-To-One relations work fine, one-to-many as well. Only many-to-many don't seem to work anymore. \r\n\r\nDo you have any workaround?"},"comment":{"url":"https://api.github.com/repos/bredikhin/barrels/issues/comments/226304944","html_url":"https://github.com/bredikhin/barrels/issues/44#issuecomment-226304944","issue_url":"https://api.github.com/repos/bredikhin/barrels/issues/44","id":226304944,"user":{"login":"neonexus","id":305472,"avatar_url":"https://avatars.githubusercontent.com/u/305472?v=3","gravatar_id":"","url":"https://api.github.com/users/neonexus","html_url":"https://github.com/neonexus","followers_url":"https://api.github.com/users/neonexus/followers","following_url":"https://api.github.com/users/neonexus/following{/other_user}","gists_url":"https://api.github.com/users/neonexus/gists{/gist_id}","starred_url":"https://api.github.com/users/neonexus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neonexus/subscriptions","organizations_url":"https://api.github.com/users/neonexus/orgs","repos_url":"https://api.github.com/users/neonexus/repos","events_url":"https://api.github.com/users/neonexus/events{/privacy}","received_events_url":"https://api.github.com/users/neonexus/received_events","type":"User","site_admin":false},"created_at":"2016-06-15T20:09:39Z","updated_at":"2016-06-15T20:09:39Z","body":"You need to use [\"through\" associations](http://sailsjs.org/documentation/concepts/models-and-orm/associations/through-associations) as I mentioned previously. There is a bug down in the Waterline core that needs to be addressed, and this is the way around that.\r\n\r\nIn other words, add the following model to your set (name it ProjectStudent.js):\r\n\r\n```javascript\r\nmodule.exports = {\r\n    attributes: {\r\n        // force ID as first column, autoPk in Sails adds it to the end\r\n        id: {\r\n            type: 'int',\r\n            primaryKey: true,\r\n            autoIncrement: true\r\n        },\r\n\r\n        project: {\r\n            model: 'project'\r\n        },\r\n        \r\n        student: {\r\n            model: 'student'\r\n        }\r\n    }\r\n};\r\n```\r\n\r\nThen Project.js:\r\n```javascript\r\nmodule.exports = {\r\n  autoPK       : true,\r\n  migrate      : 'safe',\r\n  autoCreatedAt: true,\r\n  autoUpdatedAt: true,\r\n  attributes: {\r\n     name: {\r\n       type: 'string'\r\n     },\r\n     students: {\r\n       collection: 'student',\r\n       via       : 'project',\r\n       through   : 'projectstudent'\r\n     }\r\n  },\r\n\r\n  tableName: 'projects'\r\n}\r\n```\r\n\r\nAnd Student.js:\r\n```javascript\r\nmodule.exports = {\r\n  autoPK       : true,\r\n  migrate      : 'safe',\r\n  autoCreatedAt: true,\r\n  autoUpdatedAt: true,\r\n  attributes: {\r\n     name: {\r\n       type: 'string'\r\n     },\r\n     projects: {\r\n       collection: 'project',\r\n       via       : 'student',\r\n       through   : 'projectstudent'\r\n     }\r\n  },\r\n\r\n  tableName: 'students'\r\n}\r\n```"}}
{"actor":{"display_login":"neonexus"}}