{"action":"created","issue":{"url":"https://api.github.com/repos/tgriesser/bookshelf/issues/29","labels_url":"https://api.github.com/repos/tgriesser/bookshelf/issues/29/labels{/name}","comments_url":"https://api.github.com/repos/tgriesser/bookshelf/issues/29/comments","events_url":"https://api.github.com/repos/tgriesser/bookshelf/issues/29/events","html_url":"https://github.com/tgriesser/bookshelf/issues/29","id":15792651,"number":29,"title":"`attach` with additional attributes","user":{"login":"vjpr","id":281413,"avatar_url":"https://avatars.githubusercontent.com/u/281413?v=3","gravatar_id":"","url":"https://api.github.com/users/vjpr","html_url":"https://github.com/vjpr","followers_url":"https://api.github.com/users/vjpr/followers","following_url":"https://api.github.com/users/vjpr/following{/other_user}","gists_url":"https://api.github.com/users/vjpr/gists{/gist_id}","starred_url":"https://api.github.com/users/vjpr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vjpr/subscriptions","organizations_url":"https://api.github.com/users/vjpr/orgs","repos_url":"https://api.github.com/users/vjpr/repos","events_url":"https://api.github.com/users/vjpr/events{/privacy}","received_events_url":"https://api.github.com/users/vjpr/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/tgriesser/bookshelf/labels/feature%20request","name":"feature request","color":"84b6eb"},{"url":"https://api.github.com/repos/tgriesser/bookshelf/labels/fixed","name":"fixed","color":"444444"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2013-06-20T10:45:09Z","updated_at":"2015-06-30T00:09:40Z","closed_at":"2013-12-19T17:32:57Z","body":"When I call `attach` I generally want to be able to set other attributes on the M2M relation.\r\n\r\nA common example might be a timestamp.\r\n\r\nSomething like `collection.belongsToMany(db.Models.Link).attach(link, {archived: false})`\r\n\r\nI'd also like to be able to set defaults and methods for the M2M relation.\r\n\r\n```\r\nclass CollectionsLinks extends Bookshelf.Model\r\n  defaults:\r\n    archived: false\r\n```\r\n\r\nI found the following which seems to indicate you can't pass in a model and additional params - I'd have to create a hash myself.\r\n\r\n```\r\n      // If the item is an object, it's either a model\r\n      // that we're looking to attach to this model, or\r\n      // a hash of attributes to set in the relation.\r\n      if (_.isObject(item)) {\r\n        if (item instanceof Model) {\r\n          data[relatedData.foreignKey] = item.id;\r\n        } else {\r\n          _.extend(data, item);\r\n        }\r\n      } else if (item) {\r\n        data[relatedData.foreignKey] = item;\r\n      }\r\n```\r\n\r\nAlso the comments for `belongsToMany` say:\r\n\r\n> The joinTableName may be replaced with another object, will serve as the joining model.\r\n\r\nI expected to be able to pass a `Bookshelf.Model`, whose `defaults` would be set on attach, as well as timestamps, etc.\r\n\r\nExamples of using many to many relations with additional attrs on the join table would be helpful.\r\n"},"comment":{"url":"https://api.github.com/repos/tgriesser/bookshelf/issues/comments/116884175","html_url":"https://github.com/tgriesser/bookshelf/issues/29#issuecomment-116884175","issue_url":"https://api.github.com/repos/tgriesser/bookshelf/issues/29","id":116884175,"user":{"login":"rhys-vdw","id":822105,"avatar_url":"https://avatars.githubusercontent.com/u/822105?v=3","gravatar_id":"","url":"https://api.github.com/users/rhys-vdw","html_url":"https://github.com/rhys-vdw","followers_url":"https://api.github.com/users/rhys-vdw/followers","following_url":"https://api.github.com/users/rhys-vdw/following{/other_user}","gists_url":"https://api.github.com/users/rhys-vdw/gists{/gist_id}","starred_url":"https://api.github.com/users/rhys-vdw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rhys-vdw/subscriptions","organizations_url":"https://api.github.com/users/rhys-vdw/orgs","repos_url":"https://api.github.com/users/rhys-vdw/repos","events_url":"https://api.github.com/users/rhys-vdw/events{/privacy}","received_events_url":"https://api.github.com/users/rhys-vdw/received_events","type":"User","site_admin":false},"created_at":"2015-06-30T00:09:40Z","updated_at":"2015-06-30T00:09:40Z","body":"Hi @ErisDS. Thanks for pointing this out. I'll try to update the docs soon."}}