Frage

I've got a model that has a nested property, which has more nested properties.

Let's say house hasMany pets has many legs

It works easily enough when there is just one level, but with two, I'm getting an error when deleting the pets, because the petsID is a foreign key in the legs table, and cfwheels is not deleting it first. I know I could just do the deletion myself with an extra command, but I'm wondering if there is a setting I missed that allows this kind of deletion

War es hilfreich?

Lösung

Did you try using the dependent argument on the association definitions?

// In `House.cfc`
hasMany(name="pets", dependent="delete");

// In `Pet.cfc`
hasMany(name="legs", dependent="delete");

When you call house.delete(), it should delete any associated pets, which then would delete any associated legs as well.

See hasMany() documentation and the "Dependencies" section of the Associations chapter.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top