# Delete all with has\_many

**URL:** <https://www.ruby-forum.com/t/delete-all-with-has-many/161542>\
**Category:** Rails\
**Created:** [February 27, 2009, 7:59am UTC](https://www.ruby-forum.com/t/delete-all-with-has-many/161542 "2009-02-27T07:59:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [February 27, 2009, 7:59am UTC](https://www.ruby-forum.com/t/delete-all-with-has-many/161542/1 "2009-02-27T07:59:21Z")

</div>

Im not sure using :dependent =\> delete\_all is correct here but I want  
to delete all the ApptEdits when an Appointment is updated in a  
certain situation. so i have:

@appt\_to\_edit.update\_attributes(appointment\_info)

and then i want to do something like:

@appt\_to\_edit.appt\_edits.destroy

but this does not work. i was thinking about something like  
using :dependent =\> :delete\_all, but i only want to do this after a  
specific update\_attributes call and not every one so i dont think this  
is appropriate. what is the best way to write the equivalent to the  
pseudocode: @appt\_to\_edit.appt\_edits.destroy?

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [February 27, 2009, 12:12pm UTC](https://www.ruby-forum.com/t/delete-all-with-has-many/161542/2 "2009-02-27T12:12:30Z")

</div>

@appt\_to\_edit.appt\_edits.destroy\_all

- 

Maurício Linhares  
[http://alinhavado.wordpress.com/](http://alinhavado.wordpress.com/) (pt-br) | [http://blog.codevader.com/](http://blog.codevader.com/)  
(en)
