This project is archived and is in readonly mode.

#2813 ✓resolved
ransom-briggs (at uiowa)

autosave for has_one does not work properly with primary_key option

Reported by ransom-briggs (at uiowa) | June 17th, 2009 @ 10:59 PM | in 2.3.6

Running into problems with :primary key option and autosave association - it sets it back to the id column of the parent instance when it shouldn't be saving it at all - it also sets it incorrectly

using the models from the test suite

f = Firm.new(:name => 'Firm with account_using_primary_key', :firm_id => 2)
a = Account.create(:credit_limit => 20, :firm_id => f.firm_id)

assoc = f.account_using_primary_key(true)
f.save

this code sets a.firm_id = f.id and then saves when it should not save - the test I wrote is pretty crummy - I just freeze the Account and show that it bails when trying to save the Firm - but will show the problem where it is saving when it should not

I also attached a passing patch which should do both things - alter the check if it should save - and set the proper value which is :primary_key if set, id if not

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Attachments

Referenced by

Pages