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.

Added reloadable attributes support

#459

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

State: wontfix
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Joshua Wilde
    Joshua Wilde

    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.

    June 20th, 2008 @ 09:19 PM

  2. Pavel Golubeff
  3. Jeremy Kemper
    Jeremy Kemper
    • Milestone cleared.
    • Assigned user set to Jeremy Kemper
    • State changed from new to open

    Cool.

    June 20th, 2008 @ 10:12 PM

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

    June 20th, 2008 @ 04:13 PM

  5. Pavel Golubeff
    Pavel Golubeff
    • No changes were found…

    June 20th, 2008 @ 04:13 PM

  6. Steven Soroka
    Steven Soroka

    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....

    June 20th, 2008 @ 09:38 PM

  7. Steven Soroka
    Steven Soroka

    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. ;)

    June 20th, 2008 @ 08:43 PM

  8. Pavel Golubeff
    Pavel Golubeff

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

    June 20th, 2008 @ 09:45 PM

  9. Pavel Golubeff
    Pavel Golubeff

    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?

    June 20th, 2008 @ 08:51 PM

  10. MatthewRudy
    MatthewRudy
    • 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.

    June 22nd, 2008 @ 03:03 PM

  11. Jeremy Kemper
    Jeremy Kemper
    • State changed from open to wontfix
    • Tag set to activerecord, edge, enhancement, patch, tested

    Good point, Matthew.

    August 28th, 2008 @ 07:55 AM