Added reloadable attributes support
Reported by Pavel Golubeff | June 20th, 2008 @ 04:13 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
-
Pavel Golubeff June 20th, 2008 @ 04:13 PM
- no changes were found...
-
Jeremy Kemper June 20th, 2008 @ 10:12 PM
- → Milestone changed from to 2.2
- → State changed from new to open
- → Assigned user changed from to Jeremy Kemper
Cool.
-
Pavel Golubeff October 23rd, 2008 @ 04:24 PM
- → Milestone cleared.
- → State changed from open to new
- → Assigned user cleared.
-
Pavel Golubeff June 20th, 2008 @ 04:13 PM
- no changes were found...
-
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 October 23rd, 2008 @ 04:24 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 June 20th, 2008 @ 09:45 PM
I like @post.reload_title viriant. Will try to implement it tomorrow.
-
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 June 22nd, 2008 @ 03:03 PM
- → Milestone changed from to 2.2
- → State changed from new to open
- → Assigned user changed from to Jeremy Kemper
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 August 28th, 2008 @ 07:55 AM
- → Tag changed from to activerecord edge enhancement patch tested
- → State changed from open to wontfix
Good point, Matthew.
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
Source available from github
The Git repository resides at http://github.com/rails
Check out the current development trunk (Edge Rails) with:
git clone git://github.com/rails/rails.git
Creating or reviewing a patch
See the contributor guide.
Creating a feature request
Please don't. If you want a new feature in Rails, you'll have to pull up your sleeves and get busy yourself. Or convince someone else to do it. See the contributor guide on how to get going. But posting them here is just going to lead to ticket root.
Creating a bug report
When creating a bug report, be sure to include as much relevant information as possible. Post the code sample that causes the problem. Preferably, alter the unit tests and show through either changed or added tests how the expected behavior is not occuring.
Security vulnerabilities should be reported via an email to security@rubyonrails.org, do not use trac for reporting security vulnerabilities. All content in trac is publicly available as soon as it is posted.
Then don't get your hopes up. Unless you have a "Code Red, Mission Critical, The World is Coming to an End" kinda bug, you're creating this ticket in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the ticket automatically will see any activity or that others will jump to fix it. Creating a ticket like this is mostly to help yourself start on the path of fixing the problem and for others to sign on to with a "I'm having this problem too".
