# ActiveRecord delete\_all With Sanitized Parameters?

**URL:** <https://www.ruby-forum.com/t/activerecord-delete-all-with-sanitized-parameters/56160>\
**Category:** Rails\
**Created:** [January 4, 2006, 8:03pm UTC](https://www.ruby-forum.com/t/activerecord-delete-all-with-sanitized-parameters/56160 "2006-01-04T20:03:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lanceball](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/5f9b8f/32.png) [@lanceball](https://www.ruby-forum.com/u/lanceball)\
**Post date:** [January 4, 2006, 8:03pm UTC](https://www.ruby-forum.com/t/activerecord-delete-all-with-sanitized-parameters/56160/1 "2006-01-04T20:03:24Z")

</div>

Hi there

I’m trying to delete a set of active record objects based on certain  
conditions. I’d like to do something like the following:

```
  Context.delete_all("uri IN (?)", uris)

```

But delete\_all doesn’t allow multiple arguments. Since I don’t have  
the IDs for the objects I want to delete, I can’t use delete(id), and  
have resorted to this, which is significantly slower since it has to  
instantiate each object, and there are individual SQL statements for  
each delete. Am I missing something obvious?

```
   contexts = Context.find(:all, :include => :terms,
     :conditions => ["uri IN (?)", uris])
   contexts.each do |context|
     context.destroy
   end

```

Thanks  
Lance

---

<div class="post-metadata">

**Author:** ![lanceball](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/5f9b8f/32.png) [@lanceball](https://www.ruby-forum.com/u/lanceball)\
**Post date:** [January 4, 2006, 8:23pm UTC](https://www.ruby-forum.com/t/activerecord-delete-all-with-sanitized-parameters/56160/2 "2006-01-04T20:23:05Z")

</div>

Lance B. wrote:

> ```
> Context.delete_all("uri IN (?)", uris)
> 
> ```

did you try ‘Context.delete\_all([“uri IN (?)”,uris])’ ?

---

<div class="post-metadata">

**Author:** ![lanceball](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/5f9b8f/32.png) [@lanceball](https://www.ruby-forum.com/u/lanceball)\
**Post date:** [January 4, 2006, 10:03pm UTC](https://www.ruby-forum.com/t/activerecord-delete-all-with-sanitized-parameters/56160/3 "2006-01-04T22:03:59Z")

</div>

On 1/4/06, Kevin O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Lance B. wrote:
> 
> > ```
> > Context.delete_all("uri IN (?)", uris)
> > 
> > ```
> 
> did you try ‘Context.delete\_all([“uri IN (?)”,uris])’ ?

Well, I guess we all have our moments to be _very\_embarrassed_!

Thanks - that did the trick.

Lance

---

<div class="post-metadata">

**Author:** ![lanceball](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/5f9b8f/32.png) [@lanceball](https://www.ruby-forum.com/u/lanceball)\
**Post date:** [January 4, 2006, 10:07pm UTC](https://www.ruby-forum.com/t/activerecord-delete-all-with-sanitized-parameters/56160/4 "2006-01-04T22:07:00Z")

</div>

Bad form to reply to my own post, but…

This does work, however, it has a drawback. Using context.destroy  
also removes associated rows in my habtm mapping table.  
Context.delete\_all does not. Back to the drawing board…

Lance
