realm / realm-swift

Realm is a mobile database: a replacement for Core Data & SQLite
https://realm.io
Apache License 2.0
16.32k stars 2.15k forks source link

Default value property is not working #1421

Closed marcaoas closed 9 years ago

marcaoas commented 9 years ago

Hi. I have the following defaultPropertyValues method:

Objective-C
+(NSDictionary *)defaultPropertyValues {
    return @{
             @"capture" :@"-",
             @"comment": @"-",
             @"privateInfo": @NO,
             @"date": @"",
             @"text": @"",
             @"sent": @NO,
             @"remoteId": @0,
             @"companyRemoteId": @0,
             @"proccessId": @0,
             @"dataIdentifier": @"-",
             @"link": @"-",
             @"linkType": @"-",
             @"proccessNumber": @"-",
             @"order": @0,
             @"counselType": @0,
             @"versionId":@0
             };
}

And when I save the object the following exception is thrown:

'No value or default value specified for property 'comment' in 'FZProccessProgress''

Am I doing something wrong or it is a bug?

segiddins commented 9 years ago

@marcaoas could you please share the code in which you're creating your object?

armandsLa commented 9 years ago

Having the same problem.

marcaoas commented 9 years ago

It's a Restkit request and the object is created from restkit

RKObjectManager *manager = [RKObjectManager sharedManager];
    [manager getObjectsAtPath:kProccessProgressPath parameters:params success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
        if([mappingResult array].count == 0){
            [self finish];
        } else {
            NSNumber *lastVersion = @0;
            RLMRealm *realm = [RLMRealm defaultRealm];
            [realm beginWriteTransaction];
            for(FZProccessProgress *progress in [mappingResult array]){
                FZProccessProgress *pp = [FZProccessProgress objectForPrimaryKey:[NSNumber numberWithInt:progress.remoteId]];
                if(!pp){
                    progress.read = NO;
                } else {
                    progress.read = pp.read;
                }
                [realm addOrUpdateObject:progress];
                if([NSNumber numberWithInteger:progress.versionId] > lastVersion){
                    lastVersion = [NSNumber numberWithInteger:progress.versionId];
                }
            }
            [realm commitWriteTransaction];
            [self syncWithVersion:lastVersion];
        }
    } failure:^(RKObjectRequestOperation *operation, NSError *error) {
        //TODO
        NSLog(@"%@", error);
        [self error];
    }];
segiddins commented 9 years ago

@marcaoas, I've seen this issue with RestKit usage a few times, and every time it's been related to NSNull values getting into the RestKit-mapped object. Can you check if this is indeed what is happening? I'm considering adding an option in RestKit to not map null values, which would help in that circumstance.

segiddins commented 9 years ago

@marcaoas, it would also be incredibly helpful to have an example project that replicates the issue.

marcaoas commented 9 years ago

Ok @segiddins I'll create an example project.

segiddins commented 9 years ago

@marcaoas did you end up creating an example project I could have a look at?

segiddins commented 9 years ago

@marcaoas feel free to ping me to reopen this issue if you get together an example project.