{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/26572","repository_url":"https://api.github.com/repos/rails/rails","labels_url":"https://api.github.com/repos/rails/rails/issues/26572/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/26572/comments","events_url":"https://api.github.com/repos/rails/rails/issues/26572/events","html_url":"https://github.com/rails/rails/pull/26572","id":178410722,"number":26572,"title":"Add support for `belongs_to`'s `optional` option to handle data integrity","user":{"login":"mechanicles","id":77895,"avatar_url":"https://avatars.githubusercontent.com/u/77895?v=3","gravatar_id":"","url":"https://api.github.com/users/mechanicles","html_url":"https://github.com/mechanicles","followers_url":"https://api.github.com/users/mechanicles/followers","following_url":"https://api.github.com/users/mechanicles/following{/other_user}","gists_url":"https://api.github.com/users/mechanicles/gists{/gist_id}","starred_url":"https://api.github.com/users/mechanicles/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mechanicles/subscriptions","organizations_url":"https://api.github.com/users/mechanicles/orgs","repos_url":"https://api.github.com/users/mechanicles/repos","events_url":"https://api.github.com/users/mechanicles/events{/privacy}","received_events_url":"https://api.github.com/users/mechanicles/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rails/rails/labels/activerecord","name":"activerecord","color":"0b02e1"}],"state":"closed","locked":false,"assignee":{"login":"pixeltrix","id":6321,"avatar_url":"https://avatars.githubusercontent.com/u/6321?v=3","gravatar_id":"","url":"https://api.github.com/users/pixeltrix","html_url":"https://github.com/pixeltrix","followers_url":"https://api.github.com/users/pixeltrix/followers","following_url":"https://api.github.com/users/pixeltrix/following{/other_user}","gists_url":"https://api.github.com/users/pixeltrix/gists{/gist_id}","starred_url":"https://api.github.com/users/pixeltrix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pixeltrix/subscriptions","organizations_url":"https://api.github.com/users/pixeltrix/orgs","repos_url":"https://api.github.com/users/pixeltrix/repos","events_url":"https://api.github.com/users/pixeltrix/events{/privacy}","received_events_url":"https://api.github.com/users/pixeltrix/received_events","type":"User","site_admin":false},"assignees":[{"login":"pixeltrix","id":6321,"avatar_url":"https://avatars.githubusercontent.com/u/6321?v=3","gravatar_id":"","url":"https://api.github.com/users/pixeltrix","html_url":"https://github.com/pixeltrix","followers_url":"https://api.github.com/users/pixeltrix/followers","following_url":"https://api.github.com/users/pixeltrix/following{/other_user}","gists_url":"https://api.github.com/users/pixeltrix/gists{/gist_id}","starred_url":"https://api.github.com/users/pixeltrix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pixeltrix/subscriptions","organizations_url":"https://api.github.com/users/pixeltrix/orgs","repos_url":"https://api.github.com/users/pixeltrix/repos","events_url":"https://api.github.com/users/pixeltrix/events{/privacy}","received_events_url":"https://api.github.com/users/pixeltrix/received_events","type":"User","site_admin":false}],"milestone":null,"comments":2,"created_at":"2016-09-21T17:22:06Z","updated_at":"2016-09-23T08:47:36Z","closed_at":"2016-09-23T08:47:36Z","pull_request":{"url":"https://api.github.com/repos/rails/rails/pulls/26572","html_url":"https://github.com/rails/rails/pull/26572","diff_url":"https://github.com/rails/rails/pull/26572.diff","patch_url":"https://github.com/rails/rails/pull/26572.patch"},"body":"By adding this support, the model can able to save foreign_key to either `nil` (NULL) value or to the valid foreign key value which means foreign key value must present in the foreign table. (Ref #26557)\r\n\r\n```ruby\r\nclass Post < ActiveRecord::Base\r\n  belongs_to :author, optional: :with_integrity\r\nend\r\n\r\nauthor = Author.create!\r\npost = Post.create!(author_id: author.id)\r\n\r\npost.author_id = 0 # Invalid id which is not present in the `authors` table\r\npost.save! # Should raise 'ActiveRecord::RecordInvalid' error\r\n\r\npost.author_id = nil\r\npost.save! # No Error\r\n```\r\nBased on this issue's discussion #26557. Added this feature.\r\n\r\nFeedbacks are welcome :)"},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/249137199","html_url":"https://github.com/rails/rails/pull/26572#issuecomment-249137199","issue_url":"https://api.github.com/repos/rails/rails/issues/26572","id":249137199,"user":{"login":"rafaelfranca","id":47848,"avatar_url":"https://avatars.githubusercontent.com/u/47848?v=3","gravatar_id":"","url":"https://api.github.com/users/rafaelfranca","html_url":"https://github.com/rafaelfranca","followers_url":"https://api.github.com/users/rafaelfranca/followers","following_url":"https://api.github.com/users/rafaelfranca/following{/other_user}","gists_url":"https://api.github.com/users/rafaelfranca/gists{/gist_id}","starred_url":"https://api.github.com/users/rafaelfranca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rafaelfranca/subscriptions","organizations_url":"https://api.github.com/users/rafaelfranca/orgs","repos_url":"https://api.github.com/users/rafaelfranca/repos","events_url":"https://api.github.com/users/rafaelfranca/events{/privacy}","received_events_url":"https://api.github.com/users/rafaelfranca/received_events","type":"User","site_admin":false},"created_at":"2016-09-23T08:47:36Z","updated_at":"2016-09-23T08:47:36Z","body":"Thank you for the pull request but I don't think it is a concern of the model to know about the database constraints."}}
{"actor":{"display_login":"rafaelfranca"}}