sql - How resolve my query wrong when update columns -


i have code:

@selected_ids = params[:authorization][:contract_number] @selected_ids.zip(params[:authorization][:contract_number]).each |id, value|         authorization.where(contract_number: params[:authorization][:contract_number]).update_all(value_solve: params[:authorization][:value_solve], situation: 2)       end 

haven't error, in console generate query

processing refinancingscontroller#new html   parameters: {"utf8"=>"✓", "search_employee_by_cpf"=>"11111111111", "authorization"=>{"value_solve"=>["", "4345", "454", ""], "contract_number"=>["22", "33"]}, "commit"=>"reserve"}   sql (344.2ms)  update "authorizations" set "value_solve" = '--- - '''' - ''4345'' - ''454'' - '''' ', "situation" = 2 "authorizations"."contract_number" in ('22', '33')   sql (133.1ms)  update "authorizations" set "value_solve" = '--- - '''' - ''4345'' - ''454'' - '''' ', "situation" = 2 "authorizations"."contract_number" in ('22', '33') 

and on database, values duplicated each checkbox checked.

this example column value_solve, authorization id 2

--- - '' - '4345' - '454' - '' 

column value_solve, authorization id 3

--- - '' - '4345' - '454' - '' 

please, this, how resolve , save correctly on db? need this:

sql (344.2ms)  update "authorizations" set "value_solve" = "4345", "situation" = 2 "authorizations"."contract_number" in '22'       sql (133.1ms)  update "authorizations" set "value_solve" = "454", "situation" = 2 "authorizations"."contract_number" in '33' 

you need break out 2 updates, not 1 update array value:

auth_params = params[:authorization] auth_params[:contract_number].zip(auth_params[:value_solve]).each |contract_number, value_solve|     authorization.where(contract_number: contract_number).update_all(value_solve: value_solve, situation: 2) end 

that should fire 2 updates correct arguments.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -