How do I make equipments the child (relationship) of customers?
That depends.
If it is a many-to-many: use a relationship table with FK’s to both tables
If it is a one-to-many: either use a relationship table, or store the FK in the ‘one’ table
If it is a one-to-one: either use a relationship table, or store the FK in one of the the ‘one’ tables
As for cascading deletes, the logic should be the following, assuming this:
/*
* Customer has a many-to-one relation with Order. One customer has many orders, an
* order always belongs to a single customer
*/
// get customer with id 10
$customer = new Customer(10);
// and delete it.
$customer->delete();In this setup, the Order table contains the FK ‘customer_id’.
When deleting the customer record, Datamapper will fetch the relation definition from the Customer model, and it will check if ‘cascading_delete’ is set to TRUE on the relation (which it is by default).
If so, it will check if there is a relationship table. If there is, it will delete the records from that table, but will not delete any Order records.
If there is no relationship table, it will check if Customer or Order contains the FK that defines the relation.
If the FK is in the other table, and the other table is equal to the current objects table (only true in a self-referencing relation) and the FK is in the current table, the FK will be set to NULL, and nothing will happen to the other table.
In all other cases, the related record will be deleted.
After this process, the current record itself will be deleted. If you’re using a DB capable of transactions, this entire process is wrapped in a transaction to ensure integrity.
If that doesn’t happen, then you have just found a bug.