# Conditions with update all?

**URL:** <https://www.ruby-forum.com/t/conditions-with-update-all/71091>\
**Category:** Rails\
**Created:** [October 5, 2006, 9:10am UTC](https://www.ruby-forum.com/t/conditions-with-update-all/71091 "2006-10-05T09:10:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nuno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/65b543/32.png) [@nuno](https://www.ruby-forum.com/u/nuno)\
**Post date:** [October 5, 2006, 9:10am UTC](https://www.ruby-forum.com/t/conditions-with-update-all/71091/1 "2006-10-05T09:10:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nuno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/65b543/32.png) [@nuno](https://www.ruby-forum.com/u/nuno)\
**Post date:** [October 6, 2006, 10:05am UTC](https://www.ruby-forum.com/t/conditions-with-update-all/71091/2 "2006-10-06T10:05:12Z")

</div>

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 ??

---

<div class="post-metadata">

**Author:** ![nuno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/65b543/32.png) [@nuno](https://www.ruby-forum.com/u/nuno)\
**Post date:** [October 6, 2006, 10:48am UTC](https://www.ruby-forum.com/t/conditions-with-update-all/71091/3 "2006-10-06T10:48:52Z")

</div>

You’re using update\_all incorrectly, the second parameter should not be  
a hash… See  
[http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000867](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]])

---

<div class="post-metadata">

**Author:** ![nuno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/65b543/32.png) [@nuno](https://www.ruby-forum.com/u/nuno)\
**Post date:** [October 6, 2006, 12:06pm UTC](https://www.ruby-forum.com/t/conditions-with-update-all/71091/4 "2006-10-06T12:06:17Z")

</div>

eden li wrote:

> You’re using update\_all incorrectly, the second parameter should not be  
> a hash… See  
> [Peak Obsession](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]])

Thank you works fine !
