how to make this query in activerecord:
UPDATE table_name SET column = 'value' WHERE id = 123 RETURNING other_column
I tried update_all
but it returns number of changed records, update_atributes
which returns true/false, and update
which returns the whole object.
In rails it should look like this (pseudo-code):
other_column = TableName.where(:id => 123).update_attributes(:column => 'value').returning(:other_column)
puts other_column
result_sets = Model.connection.execute("UPDATE table_name SET column = 'value' WHERE id = 123 RETURNING other_column")
result_sets.each do |result|
p result[:other_column]
end
If you just want to update a single record with id 123, why can't you do this?
TableName.update(123, :column => 'value').other_column
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With