Skip to content
This repository has been archived by the owner on Nov 25, 2019. It is now read-only.

Cannot find ignore_fields_do in the code base? #68

Open
Fykec opened this issue Dec 26, 2013 · 4 comments
Open

Cannot find ignore_fields_do in the code base? #68

Fykec opened this issue Dec 26, 2013 · 4 comments

Comments

@Fykec
Copy link

Fykec commented Dec 26, 2013

only find the validations function

@AlexDenisov
Copy link
Owner

Wiki info outdated, this fields removed. Current version uses @dynamic

@Fykec
Copy link
Author

Fykec commented Dec 26, 2013

but I really want to ignore some field, How can i do this?

@AlexDenisov
Copy link
Owner

You should create your model and mark properties as @dynamic, other properties will be ignored.

@interface User : ActiveRecord

@property (nonatomic, copy) NSString *email;
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *password; // will be ignored

@end

@implementation

@dynamic email;
@dynamic name;

@end

This way only name and email will be used by AR.

@Fykec
Copy link
Author

Fykec commented Dec 27, 2013

Hi Alex

Thank you, I know it. for example

I have a json with key

name, images, 

but I want the object have

name and images(not to save), imageURLStr(one image from images)

but if I want to

RestKit mapping images(json) to images(object)

override the method imageURLStr like bellow

- (NSString *)imageURLStr
{
    if (imageURLStr == nil)
    {
        if (images && [images count] > 0)
        {
            return [images objectAtIndex:0];
        }
    }

    return imageURLStr;
}

and

ignore images

the @dynamic will not let me do this, and If I use @synthesize, the code will not work, so I cannot to find to good way to override when use @dynamic

Then, I have to

mapping images to imageURLStr

by a transformer

RKValueTransformer *arrayToStringTransfromer = [RKBlockValueTransformer valueTransformerWithValidationBlock:^BOOL(__unsafe_unretained Class inputValueClass, __unsafe_unretained Class outputValueClass) {
    DebugLog(@"[%@|%@|%d] %@", NSStringFromClass([self class]) , NSStringFromSelector(_cmd) , __LINE__ ,@"");
    return [inputValueClass isSubclassOfClass:[NSArray class]] && [outputValueClass isSubclassOfClass:[NSString class]];
} transformationBlock:^BOOL(id inputValue, __autoreleasing id *outputValue, __unsafe_unretained Class outputClass, NSError *__autoreleasing *error) {


    if ([inputValue count] > 0)
    {
        *outputValue = [[inputValue objectAtIndex:0] copy];
    }

    return YES;
}];

RKAttributeMapping *imagesMapping = [RKAttributeMapping attributeMappingFromKeyPath:@"images" toKeyPath:@"imageURLStr"];
imagesMapping.valueTransformer = arrayToStringTransfromer;

and

not do tricky things in AR

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

No branches or pull requests

2 participants