Question

I have a mysql database with some tables in it. An example of two tables:

TABLE "dogtoilets"
- type
- location_id (FK)

TABLE "locations"
- id
- latitude
- longitude

My question is how can I clear the table "dogtoilets and also clear the locations in my locations table that are linked to dogtoilets?

Tried this but locations don't delete ...

$dogtoilets = DogToiletQuery::create()
        ->leftJoinWith('Dogtoilet.Location')
        ->find();
    $dogtoilets->delete();
Était-ce utile?

La solution

Hope this help: http://en.wikipedia.org/wiki/Foreign_key#CASCADE

Cascade will only work when you delete row in "locations", it automatically delete related rows in "dogtoilets"

In this case you should delete manually using your code.

Autres conseils

Add this to the foreign key constraints :

ON DELETE CASCADE;

It will delete all referenced objects linked with a FK.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top