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?
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:inupdate’
(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.
I think Model.update_all will do what you want. You can get the exact
syntax from Rails doc.
Long
www.edgesoft.ca
Well 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: