I believe you need to rethink your design then, you can't have a bunch of different operations that needs to be saved together spread over different actors. It's just not possible.
Maybe work with struct's instead so you can pass them between actors and have only one central actor that converts from struct objects to model objects and handles the storing and saving of objects in a single transaction.
Post
Replies
Boosts
Views
Activity
Do you have a question you want to ask?
One solution could be to actually call save() and then have a manual rollback function that when called would delete the object with a given id. That way you could hopefully avoid creating strong dependencies between your services (actors). Of course if there are cases that are more complicated than the one in your code that returns a single id a solution like this could easily become quite complex so it depends on your use case if this is doable.
Use an Array instead of a Set in your model, use Date instead of DateComponents as the element type.
If using an array gives you warnings in the console similar to
CoreData: fault: Could not materialize Objective-C class named "Array" from declared attribute value type "Array" of attribute named ...
then you can wrap the Date property in a Codable structure and use that as a type
struct ToDoDate: Codable {
let date: Date
}
In model:
var dates: [ToDoDate] = []
My guess is that this is because SQLite only support 64 bit integers so it won't work "out of the box" but require some extra work to store this type
But if you don’t like a movie anymore should a Friend or Movie really be deleted then, isn’t it the relationship that should be deleted/removed? Think about it…
How do you know T.ModelType has a property recordName?
I am pretty sure OP meant this particular sort descriptor
It makes no sense to sort against handlers.first (or at all against a to-many relationship) so I would remove this requirement
This seems like expected behavior to me and not a bug.
It could be an issue with how you handle ModelContainer in your code or possibly how you handle your ModelContext object(s)
It would help if you provided a more complete code sample. For instance what is in that where condition?
There's a lot I don't understand about your question like what Reporter really is, how the ModelActor comes into play and what you mean with the last paragraph about the fetchAll method (did you write a "not" to much?) but one issue I see in your code is that you are passing PersistentModel objects from the detached Task to the UI which means you are passing them across actor boundaries and that is something you should not do since they are not conforming to Sendable. (Which swift version are you using and do you have any concurrency checking set?)
This makes the whole solution look flawed and I would suggest that you instead fetch your objects on the MainActor using a @Query instead.
Why don't you use the @ModelActor macro instead?
@ModelActor actor ConcurrentDatabase {
private func save() {
if self.modelContext.hasChanges {
do {
try self.modelContext.save()
} catch {
...
}
}
}
}
Is this for a released app or only local in Xcode?