On 10/23/06, Dark Ambient
<sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> In order for ''dependent'' to work and all child records to
be destroyed when
> parent is, does the child foreign key have to be the id of the parent
record
> ?
> i.e.
>
> parent table | id |
> 5
>
> child table | id |parent_id|
> 1 5
This is correct. In the relationship definition you can use the option
:dependent => :destroy, this will delete all the records in the child
table that refers back to its parent. If there are no other
dependencies of the child records then you can use :dependent =>
:delete_all option. This will issue the SQL query in one shot and
improve the efficiency.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---