Skip to content

Instantly share code, notes, and snippets.

@paulocoutinhox
Created June 19, 2013 19:24
Show Gist options
  • Save paulocoutinhox/5817206 to your computer and use it in GitHub Desktop.
Save paulocoutinhox/5817206 to your computer and use it in GitHub Desktop.
##### NEW PRODUCT ######
ARLazyFetcher *fetcher = [MyProduct lazyFetcher];
[fetcher where:@"object = %@ AND object_id = %@", pObject, pObjectId, nil];
NSArray *products = [fetcher fetchRecords];
if ([products count] == 0)
{
MyProduct *product = [MyProduct newRecord];
product.title = pTitle;
product.image = pImage;
product.object = pObject;
product.object_id = pObjectId;
[product save];
}
##### FINDALL PRODUCTS ######
NSArray *products = [MyProduct allRecords];
self.tableData = nil;
self.tableData = [[NSMutableArray alloc] init];
for (MyProduct *product in products)
{
NSDictionary *newObject = [[NSDictionary alloc] initWithObjectsAndKeys:
product.title , @"title",
product.image , @"image",
product.object , @"object",
product.object_id , @"object_id",
nil];
[self.tableData addObject: newObject];
}
[self.tableView reloadData];
##### MY PRODUCT - HEADER ######
#import <ActiveRecord/ActiveRecord.h>
@interface MyProduct : ActiveRecord
@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSString *image;
@property (nonatomic, retain) NSString *object;
@property (nonatomic, retain) NSString *object_id;
+ (NSString *)recordName;
@end
##### MY PRODUCT - IMPLEMENTATION ######
#import "MyProduct.h"
@implementation MyProduct
@dynamic title;
@dynamic image;
@dynamic object;
@dynamic object_id;
+ (NSString *)recordName
{
return @"my_product";
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment