SwiftData delete underlying file when deleting entity

I have a model like this

@Model
final struct MyModel {
    var urlToUnderlyingAsset: URL
}

I'd like to delete the file at the URL whenever a MyModel gets deleted. Is that possible?

My use case is that I'm trying to keep a registry of SCNScenes, but SCNScenes are not Codable. Instead I'm storing URLs to USDZ files. If there's easier ways to keep SCNScenes in a database I'm also open to those.

SwiftData delete underlying file when deleting entity
 
 
Q