This project is archived and is in readonly mode.
Added reloadable attributes support
-
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.
-
Jeremy Kemper
- Milestone cleared.
- Assigned user set to Jeremy Kemper
- State changed from new to open
Cool.
-
Pavel Golubeff
- Milestone cleared.
- State changed from open to new
- Assigned user cleared.
-
Pavel Golubeff
- No changes were found…
-
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....
-
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. ;)
-
Pavel Golubeff
I like @post.reload_title viriant. Will try to implement it tomorrow.
-
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?
-
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 endso 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
- State changed from open to wontfix
- Tag set to activerecord, edge, enhancement, patch, tested
Good point, Matthew.
