public
Description: An objective-C implementation of ActiveRecord
Home | Edit | New

Supported relationships

ActiveRecord currently supports the following relationships

  • Has One
  • Belongs To
  • Has Many
  • Has and Belongs to Many

In order to implement your own custom relationship you must create an ARRelationship subclass implementing these methods:


@interface ARRelationship : NSObject { NSString *name; NSString *className; ARBase *record; } @property(readwrite, retain) NSString *name, *className; @property(readwrite, retain) ARBase *record;

+ (id)relationshipWithName:(NSString *)aName className:(NSString *)aClassName;
+ (id)relationshipWithName:(NSString *)aName;
- (id)initWithName:(NSString *)aName className:(NSString *)aClassName;

- (BOOL)respondsToKey:(NSString *)key supportsAdding:(BOOL *)supportsAddingRet;
- (BOOL)respondsToKey:(NSString *)key;
- (id)retrieveRecordForKey:(NSString *)key;
- (void)sendRecord:(id)record forKey:(NSString *)key;
- (void)addRecord:(id)record forKey:(NSString *)key;
- (void)removeRecord:(id)record forKey:(NSString *)key;
@end


addRecord: and removeRecord are similar to NSMutableArray’s addObject: and removeObject:atIndex: methods, they only need to be implemented for relationships that can have multiple records on either side of the relationship. Use repondsToKey:supportsAdding: to tell ARBase wether it supports adding for a certain key.

Keys are determined by putting the column name into lowercase and pluralizing or singularizing depending on the relationship (example: Has many would pluralize the objects owned but has one would not)

Last edited by aptiva, Wed Jul 30 04:33:36 -0700 2008
Home | Edit | New
Versions: