Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

autosave for has_one does not work properly with primary_key option

#2813

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

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

State: resolved
Milestone: 2.3.6
Assigned to: Eloy Duran Eloy Duran
Importance: none

Activity

  1. ransom-briggs (at uiowa)
    ransom-briggs (at uiowa)

    Adding a test for setting the foreign key as well

    June 18th, 2009 @ 02:25 PM

  2. Eloy Duran
    Eloy Duran
    • State changed from new to verified
    • Milestone changed from 2.x to 2.3.4

    I have verified and fixed this on my branch of 2-3-stable, which Micheal will look at and merge in before 2.3.4.

    http://github.com/alloy/rails/commit/e5de99082a7d151a70e8d48b96471f...

    Thanks!

    July 12th, 2009 @ 12:39 PM

  3. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.3.4 to 2.3.6

    [milestone:id#50064 bulk edit command]

    September 11th, 2009 @ 11:04 PM

  4. Repository
    Repository
    • State changed from verified to resolved

    (from [a070873771ebede9097735f07fc40720dce89c46]) Fix has_one with foreign_key and primary_key association bug which caused the associated object being lost when saving the owner. [#1756 has_one with :foreign_key & :primary_key bug state:resolved]

    Mixed in a bit from patch by ransom-briggs. [#2813 autosave for has_one does not work properly with primary_key option state:resolved]

    Signed-off-by: Eloy Duran eloy.de.enige@gmail.com
    http://github.com/rails/rails/commit/a070873771ebede9097735f07fc407...

    September 13th, 2009 @ 02:33 AM

  5. Repository
    Repository

    (from [c01be9de322ba846923340e41e69821d01541610]) Fix has_one with foreign_key and primary_key association bug which caused the associated object being lost when saving the owner. [#1756 has_one with :foreign_key & :primary_key bug state:resolved]

    Mixed in a bit from patch by ransom-briggs. [#2813 autosave for has_one does not work properly with primary_key option state:resolved]

    Signed-off-by: Eloy Duran eloy.de.enige@gmail.com
    http://github.com/rails/rails/commit/c01be9de322ba846923340e41e6982...

    September 13th, 2009 @ 02:33 AM