AlexDenisov / iActiveRecord

ActiveRecord for iOS without CoreData, only SQLite
http://alexdenisov.github.com/iActiveRecord/
MIT License
354 stars 50 forks source link

Problem when get elements that are NSNumber #43

Closed paulocoutinhox closed 11 years ago

paulocoutinhox commented 11 years ago

Hi,

I found a small problem when you fetch data from database, and the column is "NSNumber".

Instead of come a "NSNumber" with a "int" value, it come with a "NSString" value.

You need have a field that is NSNumber. Insert any data and retrieve. When you debug and inspect the column that you retrive, you will see @"1", instead of 1 (int).

AlexDenisov commented 11 years ago

Could you explain on which step have you seen this behavior? e.g. file name + line, or function name...

paulocoutinhox commented 11 years ago

My DB class:

@interface MyProductChapter : ActiveRecord

@property (nonatomic, retain) NSNumber *chapter_id;
@property (nonatomic, retain) NSString *object;
@property (nonatomic, retain) NSNumber *object_id;
@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSString *file_url;

The example method:

+ (MyProductChapter *)findFirstForObjectAndObjectId:(NSString *)object : (NSNumber *)objectId
{
    ARLazyFetcher *fetcherChapters = [MyProductChapter lazyFetcher];
    [fetcherChapters where:@"object = %@ AND object_id = %@", object, objectId, nil];
    [fetcherChapters limit:1];
    [fetcherChapters offset:0];
    [fetcherChapters orderBy:@"id"];

    NSArray *chapters = [fetcherChapters fetchRecords];

    if ([chapters count] > 0)
    {
        MyProductChapter *chapter = [chapters objectAtIndex:0];
        // the line below convert the NSString value to NSInteger, because "chapter.object_id" is NSNumber, but come as NSString from "ARLazyFetcher".
        //chapter.chapter_id = [NSNumber numberWithInteger: [chapter.object_id integerValue]];

        return chapter;
    }

    return nil;
}
AlexDenisov commented 11 years ago

Cannot reproduce. All records have a property NSNumber *id and it works fine.

paulocoutinhox commented 11 years ago

I will make an example.

AlexDenisov commented 11 years ago

Would be great :+1: