{"action":"closed","number":122,"pull_request":{"url":"https://api.github.com/repos/neumino/thinky/pulls/122","id":21268889,"html_url":"https://github.com/neumino/thinky/pull/122","diff_url":"https://github.com/neumino/thinky/pull/122.diff","patch_url":"https://github.com/neumino/thinky/pull/122.patch","issue_url":"https://api.github.com/repos/neumino/thinky/issues/122","number":122,"state":"closed","locked":false,"title":"Support merging additional link fields into joined docs","user":{"login":"simonratner","id":667283,"avatar_url":"https://avatars.githubusercontent.com/u/667283?v=3","gravatar_id":"","url":"https://api.github.com/users/simonratner","html_url":"https://github.com/simonratner","followers_url":"https://api.github.com/users/simonratner/followers","following_url":"https://api.github.com/users/simonratner/following{/other_user}","gists_url":"https://api.github.com/users/simonratner/gists{/gist_id}","starred_url":"https://api.github.com/users/simonratner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simonratner/subscriptions","organizations_url":"https://api.github.com/users/simonratner/orgs","repos_url":"https://api.github.com/users/simonratner/repos","events_url":"https://api.github.com/users/simonratner/events{/privacy}","received_events_url":"https://api.github.com/users/simonratner/received_events","type":"User","site_admin":false},"body":"Hacky hack to support storing additional fields in the n-n linking table. Example:\r\n```javascript\r\nvar A = thinky.createModel('A', {id: String});\r\nvar B = thinky.createModel('B', {id: String});\r\nvar A_B = thinky.createModel('A_B', {id: String, extra: String});\r\nA.hasAndBelongsToMany(B, 'bs', 'id', 'id');\r\nB.hasAndBelongsToMany(A, 'as', 'id', 'id');\r\n\r\nvar a = new A({id: 'a1'});\r\na.bs = [new B({id: 'b1'})];\r\na.saveAll();\r\n\r\n// Stash some extra fields on the link.\r\nA_B.get('a1_b1').update({extra: '42'});\r\n\r\nA.get('a1').getJoin({bs: true}).then(console.log);\r\n// > {\"id\": \"a1\", \"bs\": [{\"id\": \"b1\"}] }\r\nA.get('a1').getJoin({bs: {_merge: true}}).then(console.log);\r\n// > {\"id\": \"a1\", \"bs\": [{\"id\": \"b1\", \"extra\": \"42\"}] }\r\n```\r\n\r\nThis isn't necessarily the right way to implement this, but I wanted to open it for discussion. In particular, there isn't a sensible way to model the linking table without knowing the internals of `thinky`, and there is no support for saving documents merged in this way.\r\n\r\nI think a better way to implement this functionality might be with [`hasMany..through`](http://guides.rubyonrails.org/association_basics.html#the-has-many-through-association). Currently, `thinky` models `hasMany` relationships with an embedded array rather than a linking table, making that a bigger change than I had time for, but in theory it might look something like this:\r\n```javascript\r\nvar A = thinky.createModel('A', {id: String});\r\nvar B = thinky.createModel('B', {id: String});\r\nvar Link = thinky.createModel('Link', {id: String, extra: String});\r\nA.hasMany(B, 'bs', 'id', 'id', {through: Link});\r\nB.hasMany(A, 'as', 'id', 'id', {through: Link});\r\n```","created_at":"2014-09-15T23:54:03Z","updated_at":"2015-08-11T06:10:02Z","closed_at":"2015-08-11T06:10:02Z","merged_at":null,"merge_commit_sha":"15cecad1166018b33f5ea8bd079d14b19239560c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/neumino/thinky/pulls/122/commits","review_comments_url":"https://api.github.com/repos/neumino/thinky/pulls/122/comments","review_comment_url":"https://api.github.com/repos/neumino/thinky/pulls/comments{/number}","comments_url":"https://api.github.com/repos/neumino/thinky/issues/122/comments","statuses_url":"https://api.github.com/repos/neumino/thinky/statuses/55199b6effbbbc5e0ec2145f24e89b5968b1c424","head":{"label":"simonratner:feature/merge-link-docs","ref":"feature/merge-link-docs","sha":"55199b6effbbbc5e0ec2145f24e89b5968b1c424","user":{"login":"simonratner","id":667283,"avatar_url":"https://avatars.githubusercontent.com/u/667283?v=3","gravatar_id":"","url":"https://api.github.com/users/simonratner","html_url":"https://github.com/simonratner","followers_url":"https://api.github.com/users/simonratner/followers","following_url":"https://api.github.com/users/simonratner/following{/other_user}","gists_url":"https://api.github.com/users/simonratner/gists{/gist_id}","starred_url":"https://api.github.com/users/simonratner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simonratner/subscriptions","organizations_url":"https://api.github.com/users/simonratner/orgs","repos_url":"https://api.github.com/users/simonratner/repos","events_url":"https://api.github.com/users/simonratner/events{/privacy}","received_events_url":"https://api.github.com/users/simonratner/received_events","type":"User","site_admin":false},"repo":{"id":22232722,"name":"thinky","full_name":"simonratner/thinky","owner":{"login":"simonratner","id":667283,"avatar_url":"https://avatars.githubusercontent.com/u/667283?v=3","gravatar_id":"","url":"https://api.github.com/users/simonratner","html_url":"https://github.com/simonratner","followers_url":"https://api.github.com/users/simonratner/followers","following_url":"https://api.github.com/users/simonratner/following{/other_user}","gists_url":"https://api.github.com/users/simonratner/gists{/gist_id}","starred_url":"https://api.github.com/users/simonratner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simonratner/subscriptions","organizations_url":"https://api.github.com/users/simonratner/orgs","repos_url":"https://api.github.com/users/simonratner/repos","events_url":"https://api.github.com/users/simonratner/events{/privacy}","received_events_url":"https://api.github.com/users/simonratner/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/simonratner/thinky","description":"JavaScript ORM for RethinkDB","fork":true,"url":"https://api.github.com/repos/simonratner/thinky","forks_url":"https://api.github.com/repos/simonratner/thinky/forks","keys_url":"https://api.github.com/repos/simonratner/thinky/keys{/key_id}","collaborators_url":"https://api.github.com/repos/simonratner/thinky/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/simonratner/thinky/teams","hooks_url":"https://api.github.com/repos/simonratner/thinky/hooks","issue_events_url":"https://api.github.com/repos/simonratner/thinky/issues/events{/number}","events_url":"https://api.github.com/repos/simonratner/thinky/events","assignees_url":"https://api.github.com/repos/simonratner/thinky/assignees{/user}","branches_url":"https://api.github.com/repos/simonratner/thinky/branches{/branch}","tags_url":"https://api.github.com/repos/simonratner/thinky/tags","blobs_url":"https://api.github.com/repos/simonratner/thinky/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/simonratner/thinky/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/simonratner/thinky/git/refs{/sha}","trees_url":"https://api.github.com/repos/simonratner/thinky/git/trees{/sha}","statuses_url":"https://api.github.com/repos/simonratner/thinky/statuses/{sha}","languages_url":"https://api.github.com/repos/simonratner/thinky/languages","stargazers_url":"https://api.github.com/repos/simonratner/thinky/stargazers","contributors_url":"https://api.github.com/repos/simonratner/thinky/contributors","subscribers_url":"https://api.github.com/repos/simonratner/thinky/subscribers","subscription_url":"https://api.github.com/repos/simonratner/thinky/subscription","commits_url":"https://api.github.com/repos/simonratner/thinky/commits{/sha}","git_commits_url":"https://api.github.com/repos/simonratner/thinky/git/commits{/sha}","comments_url":"https://api.github.com/repos/simonratner/thinky/comments{/number}","issue_comment_url":"https://api.github.com/repos/simonratner/thinky/issues/comments{/number}","contents_url":"https://api.github.com/repos/simonratner/thinky/contents/{+path}","compare_url":"https://api.github.com/repos/simonratner/thinky/compare/{base}...{head}","merges_url":"https://api.github.com/repos/simonratner/thinky/merges","archive_url":"https://api.github.com/repos/simonratner/thinky/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/simonratner/thinky/downloads","issues_url":"https://api.github.com/repos/simonratner/thinky/issues{/number}","pulls_url":"https://api.github.com/repos/simonratner/thinky/pulls{/number}","milestones_url":"https://api.github.com/repos/simonratner/thinky/milestones{/number}","notifications_url":"https://api.github.com/repos/simonratner/thinky/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/simonratner/thinky/labels{/name}","releases_url":"https://api.github.com/repos/simonratner/thinky/releases{/id}","created_at":"2014-07-24T21:51:19Z","updated_at":"2015-04-22T18:56:09Z","pushed_at":"2015-05-21T21:11:15Z","git_url":"git://github.com/simonratner/thinky.git","ssh_url":"git@github.com:simonratner/thinky.git","clone_url":"https://github.com/simonratner/thinky.git","svn_url":"https://github.com/simonratner/thinky","homepage":null,"size":2176,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":2,"mirror_url":null,"open_issues_count":0,"forks":2,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"neumino:master","ref":"master","sha":"d9ef527a34a9acf3775b3f054eeeedf38a102a0a","user":{"login":"neumino","id":1461947,"avatar_url":"https://avatars.githubusercontent.com/u/1461947?v=3","gravatar_id":"","url":"https://api.github.com/users/neumino","html_url":"https://github.com/neumino","followers_url":"https://api.github.com/users/neumino/followers","following_url":"https://api.github.com/users/neumino/following{/other_user}","gists_url":"https://api.github.com/users/neumino/gists{/gist_id}","starred_url":"https://api.github.com/users/neumino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neumino/subscriptions","organizations_url":"https://api.github.com/users/neumino/orgs","repos_url":"https://api.github.com/users/neumino/repos","events_url":"https://api.github.com/users/neumino/events{/privacy}","received_events_url":"https://api.github.com/users/neumino/received_events","type":"User","site_admin":false},"repo":{"id":10870999,"name":"thinky","full_name":"neumino/thinky","owner":{"login":"neumino","id":1461947,"avatar_url":"https://avatars.githubusercontent.com/u/1461947?v=3","gravatar_id":"","url":"https://api.github.com/users/neumino","html_url":"https://github.com/neumino","followers_url":"https://api.github.com/users/neumino/followers","following_url":"https://api.github.com/users/neumino/following{/other_user}","gists_url":"https://api.github.com/users/neumino/gists{/gist_id}","starred_url":"https://api.github.com/users/neumino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neumino/subscriptions","organizations_url":"https://api.github.com/users/neumino/orgs","repos_url":"https://api.github.com/users/neumino/repos","events_url":"https://api.github.com/users/neumino/events{/privacy}","received_events_url":"https://api.github.com/users/neumino/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/neumino/thinky","description":"JavaScript ORM for RethinkDB","fork":false,"url":"https://api.github.com/repos/neumino/thinky","forks_url":"https://api.github.com/repos/neumino/thinky/forks","keys_url":"https://api.github.com/repos/neumino/thinky/keys{/key_id}","collaborators_url":"https://api.github.com/repos/neumino/thinky/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/neumino/thinky/teams","hooks_url":"https://api.github.com/repos/neumino/thinky/hooks","issue_events_url":"https://api.github.com/repos/neumino/thinky/issues/events{/number}","events_url":"https://api.github.com/repos/neumino/thinky/events","assignees_url":"https://api.github.com/repos/neumino/thinky/assignees{/user}","branches_url":"https://api.github.com/repos/neumino/thinky/branches{/branch}","tags_url":"https://api.github.com/repos/neumino/thinky/tags","blobs_url":"https://api.github.com/repos/neumino/thinky/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/neumino/thinky/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/neumino/thinky/git/refs{/sha}","trees_url":"https://api.github.com/repos/neumino/thinky/git/trees{/sha}","statuses_url":"https://api.github.com/repos/neumino/thinky/statuses/{sha}","languages_url":"https://api.github.com/repos/neumino/thinky/languages","stargazers_url":"https://api.github.com/repos/neumino/thinky/stargazers","contributors_url":"https://api.github.com/repos/neumino/thinky/contributors","subscribers_url":"https://api.github.com/repos/neumino/thinky/subscribers","subscription_url":"https://api.github.com/repos/neumino/thinky/subscription","commits_url":"https://api.github.com/repos/neumino/thinky/commits{/sha}","git_commits_url":"https://api.github.com/repos/neumino/thinky/git/commits{/sha}","comments_url":"https://api.github.com/repos/neumino/thinky/comments{/number}","issue_comment_url":"https://api.github.com/repos/neumino/thinky/issues/comments{/number}","contents_url":"https://api.github.com/repos/neumino/thinky/contents/{+path}","compare_url":"https://api.github.com/repos/neumino/thinky/compare/{base}...{head}","merges_url":"https://api.github.com/repos/neumino/thinky/merges","archive_url":"https://api.github.com/repos/neumino/thinky/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/neumino/thinky/downloads","issues_url":"https://api.github.com/repos/neumino/thinky/issues{/number}","pulls_url":"https://api.github.com/repos/neumino/thinky/pulls{/number}","milestones_url":"https://api.github.com/repos/neumino/thinky/milestones{/number}","notifications_url":"https://api.github.com/repos/neumino/thinky/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/neumino/thinky/labels{/name}","releases_url":"https://api.github.com/repos/neumino/thinky/releases{/id}","created_at":"2013-06-22T19:11:04Z","updated_at":"2015-08-11T02:00:09Z","pushed_at":"2015-08-11T05:38:41Z","git_url":"git://github.com/neumino/thinky.git","ssh_url":"git@github.com:neumino/thinky.git","clone_url":"https://github.com/neumino/thinky.git","svn_url":"https://github.com/neumino/thinky","homepage":null,"size":4684,"stargazers_count":414,"watchers_count":414,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":57,"mirror_url":null,"open_issues_count":39,"forks":57,"open_issues":39,"watchers":414,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/neumino/thinky/pulls/122"},"html":{"href":"https://github.com/neumino/thinky/pull/122"},"issue":{"href":"https://api.github.com/repos/neumino/thinky/issues/122"},"comments":{"href":"https://api.github.com/repos/neumino/thinky/issues/122/comments"},"review_comments":{"href":"https://api.github.com/repos/neumino/thinky/pulls/122/comments"},"review_comment":{"href":"https://api.github.com/repos/neumino/thinky/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/neumino/thinky/pulls/122/commits"},"statuses":{"href":"https://api.github.com/repos/neumino/thinky/statuses/55199b6effbbbc5e0ec2145f24e89b5968b1c424"}},"merged":false,"mergeable":false,"mergeable_state":"dirty","merged_by":null,"comments":8,"review_comments":0,"commits":6,"additions":19,"deletions":4,"changed_files":1}}