{"action":"closed","issue":{"url":"https://api.github.com/repos/tgriesser/bookshelf/issues/713","labels_url":"https://api.github.com/repos/tgriesser/bookshelf/issues/713/labels{/name}","comments_url":"https://api.github.com/repos/tgriesser/bookshelf/issues/713/comments","events_url":"https://api.github.com/repos/tgriesser/bookshelf/issues/713/events","html_url":"https://github.com/tgriesser/bookshelf/issues/713","id":71115522,"number":713,"title":"create new Model with complex relationships","user":{"login":"aaronmoodie","id":105030,"avatar_url":"https://avatars.githubusercontent.com/u/105030?v=3","gravatar_id":"","url":"https://api.github.com/users/aaronmoodie","html_url":"https://github.com/aaronmoodie","followers_url":"https://api.github.com/users/aaronmoodie/followers","following_url":"https://api.github.com/users/aaronmoodie/following{/other_user}","gists_url":"https://api.github.com/users/aaronmoodie/gists{/gist_id}","starred_url":"https://api.github.com/users/aaronmoodie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aaronmoodie/subscriptions","organizations_url":"https://api.github.com/users/aaronmoodie/orgs","repos_url":"https://api.github.com/users/aaronmoodie/repos","events_url":"https://api.github.com/users/aaronmoodie/events{/privacy}","received_events_url":"https://api.github.com/users/aaronmoodie/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-04-26T20:25:33Z","updated_at":"2015-04-28T02:00:59Z","closed_at":"2015-04-28T02:00:59Z","body":"I've got a track model that has some complex relations with other models\r\n\r\n```javascript\r\nvar Track = bookshelf.Model.extend({\r\n    tableName: 'tracks',\r\n    hasTimestamps: true,\r\n\r\n    user: function() {\r\n        return this.belongsTo('User');\r\n    },\r\n\r\n    votes: function() {\r\n        return this.hasMany('Vote');\r\n    },\r\n\r\n    tags: function() {\r\n        return this.hasMany('Tag').through('TrackTagMap');\r\n  },\r\n\r\n});\r\n```\r\n\r\nI have a working app that creates and adds a Vote when the Track is created. I'm getting really stuck trying to work out the tags however. I'm currently passing in an array of tag objects with name and id. I plan on doing a lookup for each tag, and creating the tag if it doesn't exist. \r\n\r\nI then however have to create a TrackTagMap for each tag as well. \r\n\r\nMy question is, does each of these things have to be manually, or am I overlooking a straight forward way of attaching tags to tracks without explicitly creating TrackTagMaps? "}}