Some of my models have many-to-many relationships. For example, when I add a file to a directory, a model is created from that in addition to any relationships it may contain.
I’ve incorporated SwiftData History into my front end and backend projects and it’s able to show me what has been inserted, updated, and even deleted after the file is removed from the directory. Which only returns the identifiers I’ve set to become tombstone values. All working as expected and my client can now sync with the server.
I can add and remove the same file repeatedly and I’m able to retrieve all the transactions.
However if I add another file and then fetch transactions, it crashes at .fetchHistory(_:). The errors say they cannot find the property of a model it has a many-to-many relationship with.
I omitted appending any relationships, but the errors start pointing to properties belonging to the model itself.
I’ve only managed to get this functioning by setting the @Relationship macro to a single model. Previously, I had this macro with its delete rule and inverse on other types. But doing so would crash the same way immediately and wouldn’t let me fetch history at all.
Since it crashes at fetching the history, I’m unable to proceed and the options appear to be limited for what I can do before I fetch them.
Does SwiftData History not work with many-to-many relationships or is this a bug?