开发者

insert a value into an integer column without updating it, but adding it's contents

开发者 https://www.devze.com 2022-12-12 01:41 出处:网络
ActiveRecord::Base.connection.execute \"UPDATE ventas SET costo_de_compra = #{@nuevo_costo} WHERE id = #{@vid};\"

ActiveRecord::Base.connection.execute "UPDATE ventas SET costo_de_compra = #{@nuevo_costo} WHERE id = #{@vid};"

but this updates that column valu开发者_StackOverflowe every time it's recursed, what i want is just to insert that value to the already stablished values in that column... in proper instance i want to add the values to an integer column.

Thanks in advance


I don't know Rails, but I guess something like this:

ActiveRecord::Base.connection.execute _
"UPDATE ventas SET costo_de_compra = costo_de_compra  + #{@nuevo_costo} _
WHERE id = #{@vid};"


EDIT: oh, it's an integer column. Updated.

If I understand your question right, you are trying to add to the existing value of an integer column. If you are following rails conventions, you should be able to do something like this:

@venta = Venta.find(@vid)
@venta.costo_de_compra += @nuevo_costo
@venta.save
0

精彩评论

暂无评论...
验证码 换一张
取 消