This project is archived and is in readonly mode.

#5559 ✓wontfix

reload inconsistent in AR

Reported by Kane | September 5th, 2010 @ 05:27 PM

ActiveRecord::Base#reload returns the record or throws ActiveRecord::RecordNotFound.
But AssociationProxy#reload just catches this error and returns nil.

I think its a huge problem that a record fetched through an association behaves different as a plain record. See test for example.

This hit me hard while implementing a spec which checked if some records would be destroyed with this code:

 lambda { entity.reload }.should raise_error(ActiveRecord::RecordNotFound)
 # entity was fetched through an association so reload returned nil

Comments and changes to this ticket

  • David Trasbo

    David Trasbo September 5th, 2010 @ 06:43 PM

    Whether or not that's inconsistent is rather subjective. Of course, if you try to reload a Active Record object that doesn't exist in the database anymore that should cause an error and it does.

    But personally I'd be very surprised to see an error when reloading an empty association. I definitely think this is the intended behavior. Why don't you just check to see if #reload returns nil?

  • David Trasbo

    David Trasbo September 9th, 2010 @ 08:12 AM

    • Assigned user set to “Rohit Arondekar”

    I think this can be marked wontfix.

  • Rohit Arondekar

    Rohit Arondekar October 6th, 2010 @ 05:41 AM

    • State changed from “new” to “wontfix”
    • Importance changed from “” to “Low”

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=""></a>