Forum: Ruby on Rails update_attribute... only ONE

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3d64705648512bc7155c345391e2dda4?d=identicon&s=25 Fernanda Aispuro (Guest)
on 2006-04-21 23:39
(Received via mailing list)
Hi,



I was reading the messages at
<http://wrath.rubyonrails.org/pipermail/rails/2005-...
http://wrath.rubyonrails.org/pipermail/rails/2005-...,
Subject: [Rails] update_attribute send updates every field, why?

Well, I am having the same problem, and I do have a binary column where
I am
storing files. Also, I am calling a web service so I can send the binary
file (only this column) to the SQL Server database, making a call again
would be kind of expensive.

Is there a way to update only one column instead of all of them?

Thanks you,
Fernanda
F0b14b7dbae1e90259eb946d1c841a17?d=identicon&s=25 Ken Collins (Guest)
on 2006-05-08 19:19
(Received via mailing list)
I wanted to followup on this with a solution I found. While reading
the Agile Web Development book, I found that it referenced updating
single attributes with the "find_by_sql" in where you will only
update columns that you select. Since I have a :through association,
I do not think that method was available to me.

So in order to update a single attribute to a model object, I limited
the :select option of the standard find method. So it ended up
looking something like this. I used fully qualified column names in
the select statement. I found this worked well.

     obj = User.bla.find(params[:id], :select => "bla.id, bla.title")
     obj_title = params[:title]
     obj.title = obj_title
     if obj.save!
       # etc...
     end
D0cd6b10e01bacb976b3b815a9c660bc?d=identicon&s=25 Alex Wayne (Guest)
on 2006-05-08 19:50
Ken Collins wrote:
> I wanted to followup on this with a solution I found. While reading
> the Agile Web Development book, I found that it referenced updating
> single attributes with the "find_by_sql" in where you will only
> update columns that you select. Since I have a :through association,
> I do not think that method was available to me.
>
> So in order to update a single attribute to a model object, I limited
> the :select option of the standard find method. So it ended up
> looking something like this. I used fully qualified column names in
> the select statement. I found this worked well.
>
>      obj = User.bla.find(params[:id], :select => "bla.id, bla.title")
>      obj_title = params[:title]
>      obj.title = obj_title
>      if obj.save!
>        # etc...
>      end

Nice trick, I'll have to remember that one.
This topic is locked and can not be replied to.