AlexDenisov / iActiveRecord

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

Change the default table name #33

Closed ferranabello closed 11 years ago

ferranabello commented 11 years ago

Hello, could it be possible to change the default table name?

I mean, let's suppose I have a prepopulated SQLite database with a table called "users_phones".

To have this working with this library (as far as I know) you have to create an objective-c class called exactly "users_phones". But I want this class to be called "UsersPhones" as any other class in objective-c.

So it could be great to call the class "UsersPhones" and tell the class to load the table "users_phones" instead of searching for the table "UsersPhones" or create one.

Congratulations for this great piece of code. It is really amazing!

Thanks a lot!

skiptomyliu commented 11 years ago

In your class, you can override the method "tableName" to reflect your sqlite DB export. So you can create a class called "UsersPhones", but point it to the users_phones table:

+ (NSString*) tableName{
    return @"users_phones";
}
AlexDenisov commented 11 years ago

Hi @ferranabello, @skiptomyliu almost right, but you should override recordName method

+ (NSString *)recordName {
//    return [self description];
    return @"user_phones";
}

This should work as you expect. If not, please, reopen this issue.

AlexDenisov commented 11 years ago

@ferranabello, proposed solution didn't work, so I've implemented this feature right now. You can use source code from master branch.

ferranabello commented 11 years ago

Thank you very much @AlexDenisov :+1: