Can't add values to Relationship?

Hi There,

i'm not sure if anything changed in Beta 7 or it's me being an ***** but I can't seem to update my relationship property, anyone else experienced this?

@Model final class Goal  {
    
    // More properties here
    
    @Relationship(deleteRule: .cascade, inverse: \Progress.goal) var progress: [Progress]?
    
    
    init(progress: [Progress]? = []) {
        self.progress = progress
    }
    
    func updateProgress(with value: Double) {
        // I've also tried this with having the modelContext in the initialiser
        let context = ModelContext(DataStore.container) 
        let newProgress = Progress(date: Date.now, value: value)
        newProgress.goal = self
        context.insert(newProgress)
        self.progress?.append(newProgress)
        
        // Other code
    }
}

@Model final class Progress {
    var progressDate: Date?
    var value: Double?
    var goal: Goal?
    
    init(date: Date = Date.now, value: Double = 0.0, goal: Goal? = nil) {
        self.progressDate = date
        self.value = value
        self.goal = goal
    }
}

Everytime I call the updateProgress method I get a fatal error (e.g. goal.updateProgress(with: 33.2)

The Error

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unacceptable type of value for to-one relationship: property = "goal"; desired type = NSManagedObject; given type = NSManagedObject; value = <NSManagedObject: 0x2823e0c80> (entity: Goal; id: 0x8617307020b13c03 <x-coredata://7AE46844-B3C6-46A3-B350-FC65B7CCDF8F/Goal/p17>; data: { // Properties here })

I've tried many different ways but without any luck…

In case this is a bug: FB13034172

I am also seeing a similar crash on beta 8

I'm getting the same error while running on simulator or actual device (Beta 8 and RC versions). In preview it works as expected.  "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unacceptable type of value for to-one relationship: property = "linearity"; desired type = NSManagedObject; given type = NSManagedObject; value = <NSManagedObject: 0x281bc37f0>"

It is still happening even on RC and I've tried everything:

setting goal after insertonly adding progress to goal (so no, newProgress.goal = self)making sure that the context is the same
Can't add values to Relationship?
 
 
Q