Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating referencecollection overrides data #26

Open
madsodgaard opened this issue Feb 28, 2018 · 1 comment
Open

Updating referencecollection overrides data #26

madsodgaard opened this issue Feb 28, 2018 · 1 comment

Comments

@madsodgaard
Copy link

Hello.

I am currently trying to insert a new item into a ReferenceCollection of a User object (followers ex)

As the item I am inserting already exists, right now when I try to update() on the user object I am inserting to, it overrides the data for the referenced object. I am only initating the object with an ID for the document, so it sets all the fields to null.

If the update methods also updates the references, wouldn't that be inconvienient if the other object is updated in between, would mean the data would be rolled back?


if let userSnapshot = snapshot.documents.first
                                {
                                    user.friends.insert(CHUser(id: id))
                                    user.update({ (error) in
                                        if let error = error
                                        {
                                            print(error)
                                            completion(CHError.UnknownError, nil)
                                            return
                                        }
                                        
                                        completion(nil, userSnapshot.documentID)
                                    })
                                }
@1amageek
Copy link
Owner

1amageek commented Mar 1, 2018

Hi.
I recommend you to create social features.
https://github.com/1amageek/Socialbase

It is the engineer's responsibility to decide whether it has already been saved.
Object already stored in Pring Initialize as follows.

let user: User = User(id: "USER_ID") // is not saved
let user: User = User(id: "USER_ID", value: [:]) // is saved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants