All I want to do is change one field of my object and update it in the database. I thought that this was the syntax: obj.update_attribute(:status_id, 5) but the SQL statement that''s generated it still attempting to specify values for every single field in the object. This causes me problems (one of the fields is a very long XML object) so I''m trying to avoid it. What''s the Ruby syntax that will generate just the single statement to update object_table set status_id=5 where id=xxx? Thanks! D -- 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 -~----------~----~----~----~------~----~------~--~---
> What''s the Ruby syntax that will generate just the single statement to > update object_table set status_id=5 where id=xxx? > > Thanks! > > DTry Model.update(xxx, {:status_id => 5}) According to AWDwR that should run a single update on that field, and not all of them. -- 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 -~----------~----~----~----~------~----~------~--~---
Bryan M wrote:> Model.update(xxx, {:status_id => 5}) > According to AWDwR that should run a single update on that field, and > not all of them.Thanks Bryan. Unfortunately its not working for me. Using this: Letter.update(l.id, { :status_id => Status.batchsent }) gets me this: c:/newruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connecti on_adapters/abstract_adapter.rb:120:in `log'': OCIError: ORA-01704: string litera l too long: UPDATE LETTER_TABLE SET xml_data = ''...'', recipient_email_address = ''...'', date_created = ''2006-10-13 15:33:22'', xsl_id = 2.0, user_id_created = ''...'', comments = ''...'' ..., status_id = 8, ltr_viewed = 0, is_deleted = 0, ready_for_review = 1 WHERE id = ''...'' (ActiveRecord::StatementInvalid) from c:/newruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/oracle_adapter.rb:271:in `update'' (edited for length. But that xml_data=''...'' shouldn''t be there at all ,that''s what I''m trying to prevent.) I wonder if it''s because I''m using Oracle? Maybe my next move is to test it with MySql. That won''t help me, since I''m hitting a production database I can''t change, but at least it''ll tell me where the error lies. -- 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 -~----------~----~----~----~------~----~------~--~---
Duane Morin wrote:> > All I want to do is change one field of my object and update it in the > database. I thought that this was the syntax: > > obj.update_attribute(:status_id, 5) > > but the SQL statement that''s generated it still attempting to specify > values for every single field in the object. This causes me problems > (one of the fields is a very long XML object) so I''m trying to avoid it. > What''s the Ruby syntax that will generate just the single statement to > update object_table set status_id=5 where id=xxx? >Duane, I think Model.update_all will do what you want. You can get the exact syntax from Rails doc. Long www.edgesoft.ca --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Long wrote:> Duane Morin wrote: >> update object_table set status_id=5 where id=xxx? >> > Duane, > > I think Model.update_all will do what you want. You can get the exact > syntax from Rails doc. > > Long > www.edgesoft.caWell I''ll be darned, that worked! Funny, that''s exactly the sort of thing I would have expected *not* to work, what with the "update *all*". It''s not terribly pretty: Model.update_all "status_id="+var.status.to_s, "id="+currentobj.id but heck, I can probably clean that up. As long as it works I can move on. :) Thanks!! -- 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 -~----------~----~----~----~------~----~------~--~---