AlexDenisov / iActiveRecord

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

Problem when use NSDictionary #42

Closed paulocoutinhox closed 11 years ago

paulocoutinhox commented 11 years ago

Hi,

With the current version i found one problem.

When i create one NSDictionary with json data of my webservice and set it into my ActiveRecord classes, it dont accept its values, because it i converted in primitive types.

Example:

// chapterListItem is the NSDictionary object, and it only accept objects (NSString and NSNumber) MyProductChapter *chapter = [MyProductChapter newRecord]; chapter.chapter_id = [chapterListItem objectForKey:@"chapter_id"]; //chapter_id is NSNumber in activerecord class chapter.object_id = [chapterListItem objectForKey:@"object_id"]; // object_id is NSString in activerecord class [chapter save];

Both chapter_id and object_id is an object (NSNumber and NSString).

But is an object that store a number, and when i set this objects into my MyProductChapter class that inherit from ActiveRecord, it convert it to "int" and on method "save" i got error.

ARDatabaseManager.mm LINE: 472

When is INT (the column value referenced by variable "id value = [aRecord valueForColumn:column]"), on the line: if ([value isKindOfClass:[NSNumber class]]) { , throws the exception (Line: 482).

It doesnt happen before the update. Everything is working fine.

AlexDenisov commented 11 years ago

What kind of object returns this method? [chapterListItem objectForKey:@"object_id"];

paulocoutinhox commented 11 years ago

This, is NSString, but contains a number, ex: 10. It is converted to "int" (internal column) in activerecord when i set it to activerecord attribute..

AlexDenisov commented 11 years ago

Can't reproduce.

paulocoutinhox commented 11 years ago

Hi,

I solve the problem. When i get the data from json request, it store the number(chapter_id) into NSDictionary and when i get it from dictionary, it come as number and not as string object.

I change all attributes of activerecord that receive number, from NSString to NSNumber and the problem is solved.

Thanks.

AlexDenisov commented 11 years ago

@prsolucoes, I'm glad :) So problem was on 'your' side?

paulocoutinhox commented 11 years ago

Yes.