Mondblut
Mondblut

Reputation: 329

Typo 3 Extension: Delete a record in BE and automatically delete all the referenced records?

I think (hope) this is a very basic, easy to answer question:

In my extension i enable the backend user to create and delete records. Some of these classes define one or more of their properties through the uid of the record/object of another class (with 'type' => 'select' and access to a foreign table in the TCA files). Deleting one of such records gives me the warning message:

Are you sure you want to delete this record? "Test"
[tx_icingaconfgen_domain_model_kunde:17] (There are 2 reference(s) to
this record!)

Is it possible delete the referenced records automatically?

And if so: Could i specifiy this only for certain classes?

Example:

I have a class called "host" and a class called "service"...

The class service defines a property called host via the uid of a specific "host" object. If i delete the specific "host" object/record i want all the service objects/records that reference this "host" object automatically.

BUT: If i delete a certain "service" object i don't want the "host" record to be deleted, just the "service" record.

I guess i could do this via the frontend, but i want this to be specifically possible via the backend. Is there a way to achieve this?

Upvotes: 1

Views: 158

Answers (1)

Andrei Todorut
Andrei Todorut

Reputation: 4526

In your model add the @cascade annotation to child attributes.

Example

class OrderModel
{
    /**
     * @var OrderProducts
     * @cascade
     */
    protected $products
}

Upvotes: 1

Related Questions