{"action":"closed","number":425,"pull_request":{"url":"https://api.github.com/repos/hanami/model/pulls/425","id":134303095,"html_url":"https://github.com/hanami/model/pull/425","diff_url":"https://github.com/hanami/model/pull/425.diff","patch_url":"https://github.com/hanami/model/pull/425.patch","issue_url":"https://api.github.com/repos/hanami/model/issues/425","number":425,"state":"closed","locked":false,"title":"Feature: Support for one-to-one associations","user":{"login":"mereghost","id":10281,"avatar_url":"https://avatars1.githubusercontent.com/u/10281?v=4","gravatar_id":"","url":"https://api.github.com/users/mereghost","html_url":"https://github.com/mereghost","followers_url":"https://api.github.com/users/mereghost/followers","following_url":"https://api.github.com/users/mereghost/following{/other_user}","gists_url":"https://api.github.com/users/mereghost/gists{/gist_id}","starred_url":"https://api.github.com/users/mereghost/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mereghost/subscriptions","organizations_url":"https://api.github.com/users/mereghost/orgs","repos_url":"https://api.github.com/users/mereghost/repos","events_url":"https://api.github.com/users/mereghost/events{/privacy}","received_events_url":"https://api.github.com/users/mereghost/received_events","type":"User","site_admin":false},"body":"# Support for One-To-One\r\n\r\nWithout further ado I present you: One-to-One associations support\r\n\r\n```sql lite\r\nCREATE TABLE avatars (\r\n  id integer PRIMARY KEY\r\n  url text NOT NULL\r\n  user_id integer REFERENCES users(id) ON DELETE CASCADE\r\n)\r\n\r\nCREATE TABLE users (\r\n  id integer PRIMARY KEY\r\n  name text NOT NULL\r\n)\r\n```\r\n\r\nDeclaring one is pretty simple:\r\n\r\n```ruby\r\nclass Avatar < Hanami::Entity ; end\r\nclass User < Hanami::Entity ; end\r\n\r\nclass AvatarRepository < Hanami::Repository\r\n  associations do\r\n    belongs_to :users\r\n  end\r\nend\r\n\r\nclass UserRepository < Hanami::Repository\r\n  associations do\r\n    has_one :avatar\r\n  end\r\nend\r\n```\r\n\r\n## What operations will we offer\r\n\r\n- Retrieving the associated records (`#assoc`)\r\n- Retrieving the associated record as an entity (`#one`)\r\n\r\nThese 4 operations obey the rules set by our, already shipped, `has_many` association implementation.\r\n- Adding a child record to an already existing parent (`#add`)\r\n- Creating the parent-child graph on a single call (`#create`)\r\n- Updating the associated record (`#update`)\r\n- Removing the associated record (`#remove`)\r\n- Replacing the associated record (`#replace`), this will perform a delete of the current associated record and create a new one.\r\n\r\n### The conundrum of `#add` \r\n\r\nBy default `rom` does not remove the old records when you substitute the associated record, resulting in `UNIQUE CONSTRAINT` violations, if there's such constraint, or multiple associated records if there isn't.\r\n\r\nWhat did I do to fix this? Nothing yet (and that's why it's a **WIP**), but further discussion is happening on [this rom-sql issue](https://github.com/rom-rb/rom-sql/pull/226)\r\n\r\nPlease @hanami/core and community, chime in. =)","created_at":"2017-08-05T19:52:46Z","updated_at":"2017-08-10T08:02:22Z","closed_at":"2017-08-10T08:02:22Z","merged_at":"2017-08-10T08:02:22Z","merge_commit_sha":"d005ec9d3699cb576b895e45f832929fba3a3be5","assignee":{"login":"mereghost","id":10281,"avatar_url":"https://avatars1.githubusercontent.com/u/10281?v=4","gravatar_id":"","url":"https://api.github.com/users/mereghost","html_url":"https://github.com/mereghost","followers_url":"https://api.github.com/users/mereghost/followers","following_url":"https://api.github.com/users/mereghost/following{/other_user}","gists_url":"https://api.github.com/users/mereghost/gists{/gist_id}","starred_url":"https://api.github.com/users/mereghost/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mereghost/subscriptions","organizations_url":"https://api.github.com/users/mereghost/orgs","repos_url":"https://api.github.com/users/mereghost/repos","events_url":"https://api.github.com/users/mereghost/events{/privacy}","received_events_url":"https://api.github.com/users/mereghost/received_events","type":"User","site_admin":false},"assignees":[{"login":"mereghost","id":10281,"avatar_url":"https://avatars1.githubusercontent.com/u/10281?v=4","gravatar_id":"","url":"https://api.github.com/users/mereghost","html_url":"https://github.com/mereghost","followers_url":"https://api.github.com/users/mereghost/followers","following_url":"https://api.github.com/users/mereghost/following{/other_user}","gists_url":"https://api.github.com/users/mereghost/gists{/gist_id}","starred_url":"https://api.github.com/users/mereghost/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mereghost/subscriptions","organizations_url":"https://api.github.com/users/mereghost/orgs","repos_url":"https://api.github.com/users/mereghost/repos","events_url":"https://api.github.com/users/mereghost/events{/privacy}","received_events_url":"https://api.github.com/users/mereghost/received_events","type":"User","site_admin":false}],"requested_reviewers":[{"login":"AlfonsoUceda","id":925961,"avatar_url":"https://avatars1.githubusercontent.com/u/925961?v=4","gravatar_id":"","url":"https://api.github.com/users/AlfonsoUceda","html_url":"https://github.com/AlfonsoUceda","followers_url":"https://api.github.com/users/AlfonsoUceda/followers","following_url":"https://api.github.com/users/AlfonsoUceda/following{/other_user}","gists_url":"https://api.github.com/users/AlfonsoUceda/gists{/gist_id}","starred_url":"https://api.github.com/users/AlfonsoUceda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AlfonsoUceda/subscriptions","organizations_url":"https://api.github.com/users/AlfonsoUceda/orgs","repos_url":"https://api.github.com/users/AlfonsoUceda/repos","events_url":"https://api.github.com/users/AlfonsoUceda/events{/privacy}","received_events_url":"https://api.github.com/users/AlfonsoUceda/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/hanami/model/milestones/21","html_url":"https://github.com/hanami/model/milestone/21","labels_url":"https://api.github.com/repos/hanami/model/milestones/21/labels","id":2397296,"number":21,"title":"v1.1.0","description":"","creator":{"login":"jodosha","id":5089,"avatar_url":"https://avatars1.githubusercontent.com/u/5089?v=4","gravatar_id":"","url":"https://api.github.com/users/jodosha","html_url":"https://github.com/jodosha","followers_url":"https://api.github.com/users/jodosha/followers","following_url":"https://api.github.com/users/jodosha/following{/other_user}","gists_url":"https://api.github.com/users/jodosha/gists{/gist_id}","starred_url":"https://api.github.com/users/jodosha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jodosha/subscriptions","organizations_url":"https://api.github.com/users/jodosha/orgs","repos_url":"https://api.github.com/users/jodosha/repos","events_url":"https://api.github.com/users/jodosha/events{/privacy}","received_events_url":"https://api.github.com/users/jodosha/received_events","type":"User","site_admin":false},"open_issues":3,"closed_issues":5,"state":"open","created_at":"2017-03-20T09:58:10Z","updated_at":"2017-08-10T08:02:22Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/hanami/model/pulls/425/commits","review_comments_url":"https://api.github.com/repos/hanami/model/pulls/425/comments","review_comment_url":"https://api.github.com/repos/hanami/model/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hanami/model/issues/425/comments","statuses_url":"https://api.github.com/repos/hanami/model/statuses/fd9c7189a067124695b1a9b9008cabbe4014c656","head":{"label":"hanami:one-to-one","ref":"one-to-one","sha":"fd9c7189a067124695b1a9b9008cabbe4014c656","user":{"login":"hanami","id":3210273,"avatar_url":"https://avatars1.githubusercontent.com/u/3210273?v=4","gravatar_id":"","url":"https://api.github.com/users/hanami","html_url":"https://github.com/hanami","followers_url":"https://api.github.com/users/hanami/followers","following_url":"https://api.github.com/users/hanami/following{/other_user}","gists_url":"https://api.github.com/users/hanami/gists{/gist_id}","starred_url":"https://api.github.com/users/hanami/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hanami/subscriptions","organizations_url":"https://api.github.com/users/hanami/orgs","repos_url":"https://api.github.com/users/hanami/repos","events_url":"https://api.github.com/users/hanami/events{/privacy}","received_events_url":"https://api.github.com/users/hanami/received_events","type":"Organization","site_admin":false},"repo":{"id":16760719,"name":"model","full_name":"hanami/model","owner":{"login":"hanami","id":3210273,"avatar_url":"https://avatars1.githubusercontent.com/u/3210273?v=4","gravatar_id":"","url":"https://api.github.com/users/hanami","html_url":"https://github.com/hanami","followers_url":"https://api.github.com/users/hanami/followers","following_url":"https://api.github.com/users/hanami/following{/other_user}","gists_url":"https://api.github.com/users/hanami/gists{/gist_id}","starred_url":"https://api.github.com/users/hanami/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hanami/subscriptions","organizations_url":"https://api.github.com/users/hanami/orgs","repos_url":"https://api.github.com/users/hanami/repos","events_url":"https://api.github.com/users/hanami/events{/privacy}","received_events_url":"https://api.github.com/users/hanami/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hanami/model","description":"A persistence framework with entities and repositories","fork":false,"url":"https://api.github.com/repos/hanami/model","forks_url":"https://api.github.com/repos/hanami/model/forks","keys_url":"https://api.github.com/repos/hanami/model/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hanami/model/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hanami/model/teams","hooks_url":"https://api.github.com/repos/hanami/model/hooks","issue_events_url":"https://api.github.com/repos/hanami/model/issues/events{/number}","events_url":"https://api.github.com/repos/hanami/model/events","assignees_url":"https://api.github.com/repos/hanami/model/assignees{/user}","branches_url":"https://api.github.com/repos/hanami/model/branches{/branch}","tags_url":"https://api.github.com/repos/hanami/model/tags","blobs_url":"https://api.github.com/repos/hanami/model/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hanami/model/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hanami/model/git/refs{/sha}","trees_url":"https://api.github.com/repos/hanami/model/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hanami/model/statuses/{sha}","languages_url":"https://api.github.com/repos/hanami/model/languages","stargazers_url":"https://api.github.com/repos/hanami/model/stargazers","contributors_url":"https://api.github.com/repos/hanami/model/contributors","subscribers_url":"https://api.github.com/repos/hanami/model/subscribers","subscription_url":"https://api.github.com/repos/hanami/model/subscription","commits_url":"https://api.github.com/repos/hanami/model/commits{/sha}","git_commits_url":"https://api.github.com/repos/hanami/model/git/commits{/sha}","comments_url":"https://api.github.com/repos/hanami/model/comments{/number}","issue_comment_url":"https://api.github.com/repos/hanami/model/issues/comments{/number}","contents_url":"https://api.github.com/repos/hanami/model/contents/{+path}","compare_url":"https://api.github.com/repos/hanami/model/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hanami/model/merges","archive_url":"https://api.github.com/repos/hanami/model/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hanami/model/downloads","issues_url":"https://api.github.com/repos/hanami/model/issues{/number}","pulls_url":"https://api.github.com/repos/hanami/model/pulls{/number}","milestones_url":"https://api.github.com/repos/hanami/model/milestones{/number}","notifications_url":"https://api.github.com/repos/hanami/model/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hanami/model/labels{/name}","releases_url":"https://api.github.com/repos/hanami/model/releases{/id}","deployments_url":"https://api.github.com/repos/hanami/model/deployments","created_at":"2014-02-12T08:25:42Z","updated_at":"2017-07-31T08:31:53Z","pushed_at":"2017-08-10T08:02:22Z","git_url":"git://github.com/hanami/model.git","ssh_url":"git@github.com:hanami/model.git","clone_url":"https://github.com/hanami/model.git","svn_url":"https://github.com/hanami/model","homepage":"http://hanamirb.org","size":1388,"stargazers_count":325,"watchers_count":325,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":128,"mirror_url":null,"open_issues_count":12,"forks":128,"open_issues":12,"watchers":325,"default_branch":"master"}},"base":{"label":"hanami:develop","ref":"develop","sha":"14e9841f5d6f9ad8c3bcbcd5a80b57425343c2cf","user":{"login":"hanami","id":3210273,"avatar_url":"https://avatars1.githubusercontent.com/u/3210273?v=4","gravatar_id":"","url":"https://api.github.com/users/hanami","html_url":"https://github.com/hanami","followers_url":"https://api.github.com/users/hanami/followers","following_url":"https://api.github.com/users/hanami/following{/other_user}","gists_url":"https://api.github.com/users/hanami/gists{/gist_id}","starred_url":"https://api.github.com/users/hanami/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hanami/subscriptions","organizations_url":"https://api.github.com/users/hanami/orgs","repos_url":"https://api.github.com/users/hanami/repos","events_url":"https://api.github.com/users/hanami/events{/privacy}","received_events_url":"https://api.github.com/users/hanami/received_events","type":"Organization","site_admin":false},"repo":{"id":16760719,"name":"model","full_name":"hanami/model","owner":{"login":"hanami","id":3210273,"avatar_url":"https://avatars1.githubusercontent.com/u/3210273?v=4","gravatar_id":"","url":"https://api.github.com/users/hanami","html_url":"https://github.com/hanami","followers_url":"https://api.github.com/users/hanami/followers","following_url":"https://api.github.com/users/hanami/following{/other_user}","gists_url":"https://api.github.com/users/hanami/gists{/gist_id}","starred_url":"https://api.github.com/users/hanami/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hanami/subscriptions","organizations_url":"https://api.github.com/users/hanami/orgs","repos_url":"https://api.github.com/users/hanami/repos","events_url":"https://api.github.com/users/hanami/events{/privacy}","received_events_url":"https://api.github.com/users/hanami/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hanami/model","description":"A persistence framework with entities and repositories","fork":false,"url":"https://api.github.com/repos/hanami/model","forks_url":"https://api.github.com/repos/hanami/model/forks","keys_url":"https://api.github.com/repos/hanami/model/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hanami/model/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hanami/model/teams","hooks_url":"https://api.github.com/repos/hanami/model/hooks","issue_events_url":"https://api.github.com/repos/hanami/model/issues/events{/number}","events_url":"https://api.github.com/repos/hanami/model/events","assignees_url":"https://api.github.com/repos/hanami/model/assignees{/user}","branches_url":"https://api.github.com/repos/hanami/model/branches{/branch}","tags_url":"https://api.github.com/repos/hanami/model/tags","blobs_url":"https://api.github.com/repos/hanami/model/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hanami/model/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hanami/model/git/refs{/sha}","trees_url":"https://api.github.com/repos/hanami/model/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hanami/model/statuses/{sha}","languages_url":"https://api.github.com/repos/hanami/model/languages","stargazers_url":"https://api.github.com/repos/hanami/model/stargazers","contributors_url":"https://api.github.com/repos/hanami/model/contributors","subscribers_url":"https://api.github.com/repos/hanami/model/subscribers","subscription_url":"https://api.github.com/repos/hanami/model/subscription","commits_url":"https://api.github.com/repos/hanami/model/commits{/sha}","git_commits_url":"https://api.github.com/repos/hanami/model/git/commits{/sha}","comments_url":"https://api.github.com/repos/hanami/model/comments{/number}","issue_comment_url":"https://api.github.com/repos/hanami/model/issues/comments{/number}","contents_url":"https://api.github.com/repos/hanami/model/contents/{+path}","compare_url":"https://api.github.com/repos/hanami/model/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hanami/model/merges","archive_url":"https://api.github.com/repos/hanami/model/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hanami/model/downloads","issues_url":"https://api.github.com/repos/hanami/model/issues{/number}","pulls_url":"https://api.github.com/repos/hanami/model/pulls{/number}","milestones_url":"https://api.github.com/repos/hanami/model/milestones{/number}","notifications_url":"https://api.github.com/repos/hanami/model/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hanami/model/labels{/name}","releases_url":"https://api.github.com/repos/hanami/model/releases{/id}","deployments_url":"https://api.github.com/repos/hanami/model/deployments","created_at":"2014-02-12T08:25:42Z","updated_at":"2017-07-31T08:31:53Z","pushed_at":"2017-08-10T08:02:22Z","git_url":"git://github.com/hanami/model.git","ssh_url":"git@github.com:hanami/model.git","clone_url":"https://github.com/hanami/model.git","svn_url":"https://github.com/hanami/model","homepage":"http://hanamirb.org","size":1388,"stargazers_count":325,"watchers_count":325,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":128,"mirror_url":null,"open_issues_count":12,"forks":128,"open_issues":12,"watchers":325,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/hanami/model/pulls/425"},"html":{"href":"https://github.com/hanami/model/pull/425"},"issue":{"href":"https://api.github.com/repos/hanami/model/issues/425"},"comments":{"href":"https://api.github.com/repos/hanami/model/issues/425/comments"},"review_comments":{"href":"https://api.github.com/repos/hanami/model/pulls/425/comments"},"review_comment":{"href":"https://api.github.com/repos/hanami/model/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hanami/model/pulls/425/commits"},"statuses":{"href":"https://api.github.com/repos/hanami/model/statuses/fd9c7189a067124695b1a9b9008cabbe4014c656"}},"merged":true,"mergeable":null,"rebaseable":null,"mergeable_state":"unknown","merged_by":{"login":"jodosha","id":5089,"avatar_url":"https://avatars1.githubusercontent.com/u/5089?v=4","gravatar_id":"","url":"https://api.github.com/users/jodosha","html_url":"https://github.com/jodosha","followers_url":"https://api.github.com/users/jodosha/followers","following_url":"https://api.github.com/users/jodosha/following{/other_user}","gists_url":"https://api.github.com/users/jodosha/gists{/gist_id}","starred_url":"https://api.github.com/users/jodosha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jodosha/subscriptions","organizations_url":"https://api.github.com/users/jodosha/orgs","repos_url":"https://api.github.com/users/jodosha/repos","events_url":"https://api.github.com/users/jodosha/events{/privacy}","received_events_url":"https://api.github.com/users/jodosha/received_events","type":"User","site_admin":false},"comments":3,"review_comments":0,"maintainer_can_modify":false,"commits":8,"additions":272,"deletions":2,"changed_files":6}}
{"actor":{"display_login":"jodosha"}}