{"action":"created","issue":{"url":"https://api.github.com/repos/rails-sqlserver/activerecord-sqlserver-adapter/issues/372","labels_url":"https://api.github.com/repos/rails-sqlserver/activerecord-sqlserver-adapter/issues/372/labels{/name}","comments_url":"https://api.github.com/repos/rails-sqlserver/activerecord-sqlserver-adapter/issues/372/comments","events_url":"https://api.github.com/repos/rails-sqlserver/activerecord-sqlserver-adapter/issues/372/events","html_url":"https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues/372","id":55184854,"number":372,"title":"update_attributes with accepts_nested_attributes fails","user":{"login":"jwoertink","id":2391,"avatar_url":"https://avatars.githubusercontent.com/u/2391?v=3","gravatar_id":"","url":"https://api.github.com/users/jwoertink","html_url":"https://github.com/jwoertink","followers_url":"https://api.github.com/users/jwoertink/followers","following_url":"https://api.github.com/users/jwoertink/following{/other_user}","gists_url":"https://api.github.com/users/jwoertink/gists{/gist_id}","starred_url":"https://api.github.com/users/jwoertink/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwoertink/subscriptions","organizations_url":"https://api.github.com/users/jwoertink/orgs","repos_url":"https://api.github.com/users/jwoertink/repos","events_url":"https://api.github.com/users/jwoertink/events{/privacy}","received_events_url":"https://api.github.com/users/jwoertink/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-01-22T17:42:41Z","updated_at":"2015-01-26T18:39:04Z","closed_at":null,"body":"I have these two models.\r\n```ruby\r\nclass Appointment < ActiveRecord::Base\r\n  self.table_name = \"Appointment\"\r\n  has_one :appointment_visitor, foreign_key: 'appointmentid'\r\n  accepts_nested_attributes_for :appointment_visitor\r\nend\r\n\r\nclass AppointmentVisitor < ActiveRecord::Base\r\n  self.table_name = \"AppointmentVisitor\"\r\n  belongs_to :appointment, foreign_key: 'appointmentid'\r\nend\r\n```\r\n\r\nWhen I use create, everything works fine.\r\n```ruby\r\n# this creates the appointment and appointment_visitor with association\r\nAppointment.create(rowid: guid, appointment_visitor_attributes: av_params)\r\n```\r\n\r\nWhen I try to update them using `update_attributes`, it fails with a foreign key null error\r\n\r\n```ruby\r\n@appointment = Appointment.find(params[:id])\r\n# this fails because it says that AppointmentId in the AppointmentVisitor table is null\r\n@appointment.update_attributes({rowid: guid, appointment_visitor_attributes: av_params})\r\n```\r\n\r\n```text\r\n[10] pry(Appointment)> appointment\r\n=> #<Appointment id: 52, rowstateid: 1, summary: nil, description: \"When: Thursday, January 22, 2015  9:08 AM. (UTC-08...\", employeeid: 273863, startdate: \"2015-01-22 17:08:42\", enddate: \"2015-01-22 17:08:42\", location: \"Casapiedra\", icaluid: \"1234ASDF\", icalsequence: 0, iscanceled: false, rowid: \"9DEA7AA3-348E-4C32-A723-109D3BC20207\">\r\n[11] pry(Appointment)> appointment.update_attributes(appointment_visitor_attributes: params.merge(checkedinat: Time.now))\r\n  SQL (1.6ms)  BEGIN TRANSACTION\r\n  SQL (5.1ms)  EXEC sp_executesql N'UPDATE [AppointmentVisitor] SET [appointmentid] = @0 WHERE [AppointmentVisitor].[id] = 10052; SELECT @@ROWCOUNT AS AffectedRows', N'@0 bigint', @0 = NULL  [[\"appointmentid\", nil]]\r\nTinyTds::Error: Cannot insert the value NULL into column 'AppointmentId', table 'Alice_Test_Asura.dbo.AppointmentVisitor'; column does not allow nulls. UPDATE fails.: EXEC sp_executesql N'UPDATE [AppointmentVisitor] SET [appointmentid] = @0 WHERE [AppointmentVisitor].[id] = 10052; SELECT @@ROWCOUNT AS AffectedRows', N'@0 bigint', @0 = NULL\r\n  SQL (1.3ms)  IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION\r\nActiveRecord::StatementInvalid: TinyTds::Error: Cannot insert the value NULL into column 'AppointmentId', table 'Alice_Test_Asura.dbo.AppointmentVisitor'; column does not allow nulls. UPDATE fails.: EXEC sp_executesql N'UPDATE [AppointmentVisitor] SET [appointmentid] = @0 WHERE [AppointmentVisitor].[id] = 10052; SELECT @@ROWCOUNT AS AffectedRows', N'@0 bigint', @0 = NULL\r\nfrom /Users/jeremy/.rvm/gems/ruby-2.1.5@ard-checkin/gems/activerecord-sqlserver-adapter-4.1.0/lib/active_record/connection_adapters/sqlserver/database_statements.rb:423:in `each'\r\n[12] pry(Appointment)> appointment.appointment_visitor\r\n=> #<AppointmentVisitor id: 10052, rowstateid: 1, appointmentid: nil, title: nil, firstname: \"Selmer\", middlename: nil, lastname: \"Pagac\", suffix: nil, displayname: nil, phonenumber: nil, organizationname: nil, email: \"mckenzie@brakus.co.uk\", checkedinat: nil, checkedoutat: nil>\r\n[13] pry(Appointment)> av\r\n=> #<AppointmentVisitor id: 10052, rowstateid: 1, appointmentid: 52, title: nil, firstname: \"Selmer\", middlename: nil, lastname: \"Pagac\", suffix: nil, displayname: nil, phonenumber: nil, organizationname: nil, email: \"mckenzie@brakus.co.uk\", checkedinat: nil, checkedoutat: nil>\r\n```\r\n\r\nI'm not sure why it wants to set the appointmentid to nil, but I'm not familiar with SQL Server, or this gem so I may just have something setup wrong too."},"comment":{"url":"https://api.github.com/repos/rails-sqlserver/activerecord-sqlserver-adapter/issues/comments/71512734","html_url":"https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues/372#issuecomment-71512734","issue_url":"https://api.github.com/repos/rails-sqlserver/activerecord-sqlserver-adapter/issues/372","id":71512734,"user":{"login":"metaskills","id":2381,"avatar_url":"https://avatars.githubusercontent.com/u/2381?v=3","gravatar_id":"","url":"https://api.github.com/users/metaskills","html_url":"https://github.com/metaskills","followers_url":"https://api.github.com/users/metaskills/followers","following_url":"https://api.github.com/users/metaskills/following{/other_user}","gists_url":"https://api.github.com/users/metaskills/gists{/gist_id}","starred_url":"https://api.github.com/users/metaskills/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/metaskills/subscriptions","organizations_url":"https://api.github.com/users/metaskills/orgs","repos_url":"https://api.github.com/users/metaskills/repos","events_url":"https://api.github.com/users/metaskills/events{/privacy}","received_events_url":"https://api.github.com/users/metaskills/received_events","type":"User","site_admin":false},"created_at":"2015-01-26T18:39:04Z","updated_at":"2015-01-26T18:39:04Z","body":">  something similar with an app using postgres\r\n\r\nCould you spin up a Rails app, make a small migration matching the minimial schema of the above models, then reproduce this to confirm? If so, I can take it from there. Thanks again!"}}