'Dependent' question

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

or could the foreign key be another field that ties all the records
together, say a user_id ?

Stuart


On 10/23/06, Dark A. [email protected] 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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs