AlexDenisov / iActiveRecord

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

What's the syntax for a 'has_one' relationship? #52

Closed ghost closed 11 years ago

ghost commented 11 years ago

I haven't found a way to do the 'has_one' relationship between two models. Is that possible? Thanks for any help.

AlexDenisov commented 11 years ago

Hm... Good question, I don't know why, but this feature is not implemented. But seems that implementation is very easy. For example:

@interface User : ActiveRecord
- (Project *)project;
@end

@implementation User

- (Project *)project
{
    return [[[Project lazyFetcher] where:@"user.id = %@", self.id] firstObject];
}

@end

setProject may looks very similar.

ghost commented 11 years ago

What about the Destroy Dependency?

AlexDenisov commented 11 years ago

The same as setProject, find record and remove it manually.

ghost commented 11 years ago

OK I found a way to do it. Thanks for the help and I'm really waiting to see the new version! P.S. The fetcher should be [where:@"'project'.'userId' = %@", self.id] (doesn't work otherwise)

Have a good day! :wink:

AlexDenisov commented 11 years ago

Yep, you're right!

Thank you :smile: