Conditions with update all?

Hello, I don’t understand why

Mouvement.update_all(‘etat = false’, :conditions => [“id_paire = ?”,
params[:id_paire]])

generates these SQL statements

UPDATE mouvements SET etat = false WHERE (conditionsid_paire =
?1f194375-f715-4493-bf21-9269aafc7cff)

I presume I could write
Mouvement.update_all(‘etat = false’, “id_paire =
‘#{params[:id_paire]}’”)

But I don’t understandt why ! The first solution seems more coherent
with the way we express conditions with the find_XXX methods…

Any idea ?

Thanks

nuno wrote:

Mouvement.update_all(‘etat = false’, :conditions => [“id_paire = ?”,
params[:id_paire]])

generates these SQL statements

UPDATE mouvements SET etat = false WHERE (conditionsid_paire =
?1f194375-f715-4493-bf21-9269aafc7cff)

I presume I could write
Mouvement.update_all(‘etat = false’, “id_paire =
‘#{params[:id_paire]}’”)

But I don’t understandt why ! The first solution seems more coherent
with the way we express conditions with the find_XXX methods…

Any thoughts ??

You’re using update_all incorrectly, the second parameter should not be
a hash… See
http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000867

In your case you should change your code to:
Mouvement.update_all(‘etat = false’, [“id_paire = ?”,
params[:id_paire]])

eden li wrote:

You’re using update_all incorrectly, the second parameter should not be
a hash… See
Peak Obsession

In your case you should change your code to:
Mouvement.update_all(‘etat = false’, [“id_paire = ?”,
params[:id_paire]])

Thank you works fine !