# Deleting children

**URL:** <https://www.ruby-forum.com/t/deleting-children/133091>\
**Category:** Rails\
**Created:** [March 27, 2008, 4:59pm UTC](https://www.ruby-forum.com/t/deleting-children/133091 "2008-03-27T16:59:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sjglazer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ee59a6/32.png) [@sjglazer](https://www.ruby-forum.com/u/sjglazer)\
**Post date:** [March 27, 2008, 4:59pm UTC](https://www.ruby-forum.com/t/deleting-children/133091/1 "2008-03-27T16:59:45Z")

</div>

Hello again,

What is the best way to delete all children of a parent in a controller.  
For example I have restaurants with a has\_many association to  
boundaries. I would like to do something like this:

@restaurant.boundaries.delete\_all

is it possible?

steve

---

<div class="post-metadata">

**Author:** ![sjglazer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ee59a6/32.png) [@sjglazer](https://www.ruby-forum.com/u/sjglazer)\
**Post date:** [March 27, 2008, 5:04pm UTC](https://www.ruby-forum.com/t/deleting-children/133091/2 "2008-03-27T17:04:28Z")

</div>

On Thu, Mar 27, 2008 at 04:59:45PM +0100, Steve G. wrote:

> What is the best way to delete all children of a parent in a controller.  
> For example I have restaurants with a has\_many association to  
> boundaries. I would like to do something like this:
> 
> @restaurant.boundaries.delete\_all
> 
> is it possible?

Look at collection.clear under  
[http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html#M001103](http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html#M001103)

> steve  
> –Greg

---

<div class="post-metadata">

**Author:** ![sjglazer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ee59a6/32.png) [@sjglazer](https://www.ruby-forum.com/u/sjglazer)\
**Post date:** [March 27, 2008, 5:12pm UTC](https://www.ruby-forum.com/t/deleting-children/133091/3 "2008-03-27T17:12:13Z")

</div>

Will do - thanks greg!

Gregory S. wrote:

> On Thu, Mar 27, 2008 at 04:59:45PM +0100, Steve G. wrote:
> 
> > What is the best way to delete all children of a parent in a controller.  
> > For example I have restaurants with a has\_many association to  
> > boundaries. I would like to do something like this:
> > 
> > @restaurant.boundaries.delete\_all
> > 
> > is it possible?
> 
> Look at collection.clear under  
> [Peak Obsession](http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html#M001103)
> 
> > steve  
> > –Greg
