Skip to content

The update operation doesn't work  #333

@wugang8068

Description

@wugang8068

What

when I update the entity first it works , but it failed when I update it again with different data;

Context

Here is my code:
// I called flowed function first , and it worked when I restart my app.

static func storeAuth(
        grantType:String,
        clientId:Int16,
        clientSecret:String
        ) -> Bool{
        let auth = self.getUserAuth();
        if auth == nil{
            do{
                try AppUser.db.operation({ (context, save) throws in
                    let auth:UserAuth = try context.new();
                    auth.grantType = grantType;
                    auth.clientId = clientId;
                    auth.clientSecret = clientSecret
                    try context.insert(auth)
                    save()
                })
                return true
            }catch{
                debugPrint(error.localizedDescription)
                return false;
            }
        }else{
            do{
                try AppUser.db.operation({ (context, save) throws in
                    auth?.grantType = grantType;
                    auth?.clientId = clientId;
                    auth?.clientSecret = clientSecret
                    save()
                })
                return true;
            }catch{
                debugPrint(error.localizedDescription)
                return false;
            }
        }
    }

// and I call this function to update it again, but when I restart my app, the updated data was not stored. the data was that updated before;

static func updateAuthToken(expiresIn:Int,
                                refreshToken:String,
                                tokenType:String,
                                accessToken:String){
        let auth = self.getUserAuth();
        if auth != nil{
            do{
                try AppUser.db.operation({ (context, save) throws in
                    auth?.tokenExpiredAt = NSDate().addingSeconds(expiresIn) as NSDate?
                    auth?.refreshToken = refreshToken
                    auth?.tokenType = tokenType
                    auth?.accessToken = accessToken
                    save()
                })
            }catch{
                debugPrint(error.localizedDescription)
            }
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions