Running something like:
@users = User.find (: first ,: select => "first name, last name, salary") for @user in @users do @ user.salary = 100000 @ user.save end
After that, users are not updated in the Mysql table.
ActiveRecord does not know the identifier of the object to save data. Therefore, include the id field in: select, as shown below:
@users = User.find (: first ,: select => "id, name, lastname, pay")
, ., : select. , . vars (@). @user var. @users, :
@users = User.find(:all, :select => "id, name, lastname, salary") @users.each do |user| user.salary = 10000 user.save end
ActiveRecord update_all . , .
.update .update_attributes: ( .save, )
Using .save! will also throw an error if it does not save.
I understand that this is a rather old question at the moment, but the correct answer, I believe that any objects returned by: select, are read-only.
See the official Rails guide for Active Record queries, section 3.2:http://guides.rubyonrails.org/active_record_querying.html
Curiously, I do not see this documented in the API.
Source: https://habr.com/ru/post/1697070/More articles:How to use RegisterClientScriptBlock to register JavaScript? - javascriptReading file changes in real time using .NET. - fileDoes DataGrid support CE 5.0 Compact Framework.NET? - .netChange .xla file with MSBuild - excel-vbahttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1697069/converting-sql-result-sets-to-xml&usg=ALkJrhhknTUBe3WQY5BN_jS2Q_t34sDYxQHow to choose a CMS / Portal solution for a small site (s)? - comparisonHow can I create a human-readable script for each DTS package on the SQL server? - packagesTestDriven.Net does not find tests - .netAre proxy properties a good style? - c #If it is decided that our system needs major repairs, what is the best way to do this? - pythonAll Articles