i have a migration script that looks like this: def self.up rename_column :books, :finalizing, :progress_step change_column :books, :progress_step, :integer, :length=>2 Book.find(:all).each do |book| book.update_attributes(:progress_step=>3) if book.published_at book.update_attributes(:progress_step=>1) if !book.published_at book.update_attributes(:views=>0) if !book.views end puts "rebuilding ferret index" Rake::Task["ferret:rebuild_index"].invoke end When I checked the database fields, it turns out that progress step is still NULL. Do you guys have any idea why this could be? Do I need to do book.reload or something? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rob Biedenharn
2007-May-16 10:07 UTC
Re: update_attributes not working in self.up migration
On May 16, 2007, at 3:01 AM, Aryk Grosz wrote:> i have a migration script that looks like this: > > def self.up > rename_column :books, :finalizing, :progress_step > change_column :books, :progress_step, :integer, :length=>2 > Book.find(:all).each do |book| > book.update_attributes(:progress_step=>3) if book.published_at > book.update_attributes(:progress_step=>1) if !book.published_at > book.update_attributes(:views=>0) if !book.views > end > puts "rebuilding ferret index" > Rake::Task["ferret:rebuild_index"].invoke > end > > When I checked the database fields, it turns out that progress step is > still NULL. > > Do you guys have any idea why this could be? > > Do I need to do book.reload or something?Look at the difference in what "update_attributes" (with an "s") does compared to "update_attribute". You want the singular form for what you''re doing. The plural version replaces the entire attributes property of the object. -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bob Showalter
2007-May-16 15:34 UTC
Re: update_attributes not working in self.up migration
On 5/16/07, Aryk Grosz <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > i have a migration script that looks like this: > > def self.up > rename_column :books, :finalizing, :progress_step > change_column :books, :progress_step, :integer, :length=>2 > Book.find(:all).each do |book| > book.update_attributes(:progress_step=>3) if book.published_at > book.update_attributes(:progress_step=>1) if !book.published_at > book.update_attributes(:views=>0) if !book.views > end > puts "rebuilding ferret index" > Rake::Task["ferret:rebuild_index"].invoke > end > > When I checked the database fields, it turns out that progress step is > still NULL. > > Do you guys have any idea why this could be? > > Do I need to do book.reload or something?You need to call Book.reset_column_information There''s an example of this in the API docs for ActiveRecord::Migration. Look for "Using a model after changing its table" --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bob Showalter
2007-May-16 15:39 UTC
Re: update_attributes not working in self.up migration
On 5/16/07, Rob Biedenharn <Rob-GBZH0y1GwQfnZcttdmLDtcI/UQi/AW5J@public.gmane.org> wrote:> > Look at the difference in what "update_attributes" (with an "s") does > compared to "update_attribute". You want the singular form for what > you''re doing. The plural version replaces the entire attributes > property of the object. >I''m pretty sure that''s not correct. You can update only a subset of the attributes with this method. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rob Biedenharn
2007-May-16 20:19 UTC
Re: update_attributes not working in self.up migration
On May 16, 2007, at 11:39 AM, Bob Showalter wrote:> On 5/16/07, Rob Biedenharn <Rob-GBZH0y1GwQfnZcttdmLDtcI/UQi/AW5J@public.gmane.org> wrote: >> Look at the difference in what "update_attributes" (with an "s") does >> compared to "update_attribute". You want the singular form for what >> you''re doing. The plural version replaces the entire attributes >> property of the object. >> > > I''m pretty sure that''s not correct. You can update only a subset of > the attributes with this method.You''re correct, Bob. I let my old habits get the better of me and assumed that self.attributes=attributes;save was doing a simple writer. Silly me! -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yeah I was a little worried, because I like passing my updates as hashes, I tend to use update_attributes A LOT, even on single attribute assignments. It seems like that only real difference is that update_attributes saves with validation. Is their a huge performance decrease with using update_attributes since it calls the attributes= EXCEPT for the fact that it runs validations of course? Be very careful with your answer, I might get a heart attack having to modify all my updates. =) Aryk -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mark Reginald James
2007-May-16 20:53 UTC
Re: update_attributes not working in self.up migration
Aryk Grosz wrote:> Yeah I was a little worried, because I like passing my updates as > hashes, > > I tend to use update_attributes A LOT, even on single attribute > assignments. > > It seems like that only real difference is that update_attributes saves > with validation.update_attributes will also not update protected attributes.> Is their a huge performance decrease with using update_attributes since > it calls the attributes= EXCEPT for the fact that it runs validations of > course?It depends on how expensive validation is, and how important it is to have a sanity check on the internal updates you make to form and non-form attributes. -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Not quite sure what you mean by the internal updates to form and non-form attributes. BTW, how can an attribute in the database be protected? And what does that exactly mean? Mark Reginald James wrote:> Aryk Grosz wrote: >> Yeah I was a little worried, because I like passing my updates as >> hashes, >> >> I tend to use update_attributes A LOT, even on single attribute >> assignments. >> >> It seems like that only real difference is that update_attributes saves >> with validation. > > update_attributes will also not update protected attributes. > >> Is their a huge performance decrease with using update_attributes since >> it calls the attributes= EXCEPT for the fact that it runs validations of >> course? > > It depends on how expensive validation is, and how important it > is to have a sanity check on the internal updates you make to > form and non-form attributes. > > -- > We develop, watch us RoR, in numbers too big to ignore.-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
ooh woops, nevermind about the protected attribute question -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mark Reginald James
2007-May-16 21:25 UTC
Re: update_attributes not working in self.up migration
Aryk Grosz wrote:> Not quite sure what you mean by the internal updates to form and > non-form attributes.Updates to attributes, both those normally used in posted client forms and internal-only attributes, unrelated to form postings.> BTW, how can an attribute in the database be protected? And what does > that exactly mean?See: http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M001006 -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---