This project is archived and is in readonly mode.

#459 ✓wontfix
Pavel Golubeff

Added reloadable attributes support

Reported by Pavel Golubeff | June 20th, 2008 @ 09:19 PM

I would suggest either @post.reload_title! or @post.reload(:title). Just a plain exclamation mark doesn't convey any information about what it does, especially not that it reloads the attribute.

Comments and changes to this ticket

  • Jeremy Kemper

    Jeremy Kemper June 20th, 2008 @ 10:12 PM

    • Milestone cleared.
    • Assigned user set to “Jeremy Kemper”
    • State changed from “new” to “open”

    Cool.

  • Pavel Golubeff

    Pavel Golubeff June 20th, 2008 @ 04:13 PM

    • Milestone cleared.
    • State changed from “open” to “new”
    • Assigned user cleared.
  • Pavel Golubeff

    Pavel Golubeff June 20th, 2008 @ 04:13 PM

    • no changes were found...
  • Steven Soroka

    Steven Soroka June 20th, 2008 @ 09:38 PM

    I agree with Joshua. reload() was more what I was thinking. I'm a little confused as to why I can't find reload! anywhere in activerecord though....

  • Steven Soroka

    Steven Soroka June 20th, 2008 @ 08:43 PM

    Like the idea, hate the use of ! to do it.

    I'd maybe update the existing .reload! method to take an array of attributes to update, instead of all by default.

    @post.reload!(:title) => 'new title from db'

    much nicer. ;)

  • Pavel Golubeff

    Pavel Golubeff June 20th, 2008 @ 09:45 PM

    I like @post.reload_title viriant. Will try to implement it tomorrow.

  • Pavel Golubeff

    Pavel Golubeff June 20th, 2008 @ 08:51 PM

    Steven, thanks for the advise. I thought of extending reload! method. But i did not implement it, because in this case it's not clean, what will it return, a post or an attribute value. What do you think?

  • MatthewRudy

    MatthewRudy June 22nd, 2008 @ 03:03 PM

    • Milestone cleared.
    • Assigned user set to “Jeremy Kemper”
    • State changed from “new” to “open”

    Am I missing something?

    Doesn't this work already?

    object.reload(options)

    actually does

    def reload(options = nil)
            clear_aggregation_cache
            clear_association_cache
            @attributes.update(self.class.find(self.id, options).instance_variable_get('@attributes'))
            @attributes_cache = {}
            self
          end
    

    so object.reload(:select => "name")

    will already just reload the "name" attribute

    here's a working example

    >> Event.create(:name => "first name", :description => "first description")
    => #<Event id: 1, name: "first name", description: "first description">
    
    >> e1 = Event.find(1)
    => #<Event id: 1, name: "first name", description: "first description">
    >> e2 = Event.find(1)
    => #<Event id: 1, name: "first name", description: "first description">
    
    >> e1.name
    => "first name"
    >> e1.description
    => "first description"
    
    >> e2.update_attributes(:name => "second name", :description => "second description")
    => true
    >> e2
    => #<Event id: 1, name: "second name", description: "second description">
    
    >> e1.reload(:select => "name")
    => #<Event id: 1, name: "second name", description: "first description">
    >> e1.name
    => "second name"
    >> e1.description
    => "first description"
    
    >> e1.reload
    => #<Event id: 1, name: "second name", description: "second description">
    >> e1.name
    => "second name"
    >> e1.description
    => "second description"
    

    so it seems this functionality already exists.

  • Jeremy Kemper

    Jeremy Kemper August 28th, 2008 @ 07:55 AM

    • State changed from “open” to “wontfix”
    • Tag set to activerecord, edge, enhancement, patch, tested

    Good point, Matthew.

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>

Attachments

Pages