How to delete related records (here: select-data-view)

Hi,

a question about how to delete related records correctly.

following object (event):

	property name="adpartner"    relationship="many-to-many" relatedto="adpartner";
	property name="session"   	 relationship="one-to-many"	relatedTo="session" 			relationshipkey="veranstaltung";
	property name="attendees"    relationship="select-data-view" relatedTo="attendee" relationshipKey="eventid" ondelete="cascade";

When I delete the “event” record via the default GUI function, Preside asks me what to do wiht the blocking records in “session”. No info about the other two relations and the m:n records are still there. The ondelete option has no effect.

Question: Shouldn’t the related records for the m:n fields be deleted also?

What is a best practise here?

Thanks
Michi

It will depend on the nature of the relationship.

In the session table, presumably there is a many-to-one required field. Required relationships here will dictate that we prompt for deletion. If not required, we would just update and set NULL when the related record is deleted.

By default we auto cascade delete many-to-many relationships and do not prompt for deletion on them.

On any many-to-one relationship, you can define ondelete behaviour. The default for required fields is “error” and the options are:

  • “error” (default for required relationship props)
  • “cascade” (default for many-to-many auto relationship records)
  • “set-null” (default for non-required relationship props)

Select data views cannot be considered here as they are not clearly defined relationships that we can necessarily know how to block / or not.

1 Like