netreconlab / Parse-Swift

The original (OG) Swift SDK for Parse Platform (iOS, macOS, watchOS, tvOS, visionOS, Linux, Android, Windows). This repo is maintained by Parse-Swift's original developer and all new features and bug fixes will occur here.
https://swiftpackageindex.com/netreconlab/Parse-Swift/documentation
Apache License 2.0
59 stars 6 forks source link

Adding a relationship to a mergeable object #125

Closed bcbeta closed 8 months ago

bcbeta commented 1 year ago

New Issue Checklist

Issue Description

When adding new relationship objects to an existing mergeable object, "Object not found" error is thrown.

Steps to reproduce

var photos = [PFPhoto]()
for photoURL in photoURLs{
        var pfPhoto = PFPhoto()
        pfPhoto.thumbnailURL = photoURL
        pfPhoto.fullURL = photoURL
        photos.append(pfPhoto)
      }
      if photos.count > 0 {
               var updatedObservation = existingObservation.mergeable
               updatedObservation.observationPhotos = photos
                 _ = try await updatedObservation.save()
                  }
           }
      }
        catch {
             print(error)
           }

Actual Outcome

Save the pfPhoto and observation objects.

Expected Outcome

Throws "object not found" error

Environment

Client

Server

cbaker6 commented 1 year ago

Are you able to take a shot at a pull request with a fix and test case? If so, I’ll review it

bcbeta commented 1 year ago

Unfortunately I don't have the knowledge/skill to do this. Maybe someone else will encounter this issue and come up with a fix.

cbaker6 commented 8 months ago

Looking at this further, I believe the issue is you are trying to update relationships to objects that haven't been saved yet. Is your problem fixed if you photos.saveAll() first and then update the relationships?

cbaker6 commented 8 months ago

Feel free to reopen if my solution above doesn’t work.