Pregunta

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();
¿Fue útil?

Solución

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.

Otros consejos

Add this to the foreign key constraints :

ON DELETE CASCADE;

It will delete all referenced objects linked with a FK.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top