-
Notifications
You must be signed in to change notification settings - Fork 0
/
OTRestManagedModel.h
108 lines (85 loc) · 2.71 KB
/
OTRestManagedModel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//
// OTManagedModel.h
// OTRestFramework
//
// Created by Blake Watters on 8/14/09.
// Copyright 2009 Two Toasters. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import "OTRestModelMappableProtocol.h"
#import "OTRestModelManager.h"
@interface OTRestManagedModel : NSManagedObject <OTRestModelMappable> {
}
/**
* The Core Data managed object context from the OTRestModelManager's objectStore
* that is managing this model
*/
+ (NSManagedObjectContext*)managedObjectContext;
/**
* The NSEntityDescription for the Subclass
* defaults to the subclass className, may be overridden
*/
+ (NSEntityDescription*)entity;
/**
* Returns an initialized NSFetchRequest for the entity, with no predicate
*/
+ (NSFetchRequest*)request;
+ (NSArray*)collectionWithRequest:(NSFetchRequest*)request;
+ (id)objectWithRequest:(NSFetchRequest*)request;
+ (NSArray*)collectionWithPredicate:(NSPredicate*)predicate;
+ (id)objectWithPredicate:(NSPredicate*)predicate;
+ (NSArray*)allObjects;
/**
* Creates a new OTManagedModel and inserts it into the managedObjectContext.
*/
+ (id)newObject;
/**
* The primaryKey property mapping, defaults to @"railsID"
*/
+ (NSString*)primaryKey;
/**
* The name of the primary key in the server-side data payload. Defaults to @"id" for Rails generated XML/JSON
*/
+ (NSString*)primaryKeyElement;
/**
* Will find the existing object with the primary key of 'value' and return it
* or return nil
*/
+ (id)findByPrimaryKey:(id)value;
/**
* Defines the properties which the OTModelMapper maps elements to
*/
+ (NSDictionary*)elementToPropertyMappings;
/**
* Defines the relationship properties which the OTModelMapper maps elements to
* @"user" => @"user" will map the @"user" element to an NSObject* property @"user"
* @"memberships > user" => @"users" will map the @"user" elements in the @"memberships" element
* to an NSSet* property named @"users"
*/
+ (NSDictionary*)elementToRelationshipMappings;
/**
* Returns all the XML/JSON element names for the properties of this model
*/
+ (NSArray*)elementNames;
/**
* Returns all the Managed Model property names of this model
*/
+ (NSArray*)elementNames;
// The server side name of the model?
+ (NSString*)modelName;
- (NSDictionary*)elementNamesAndPropertyValues;
/**
* Save the object into the managed object context
*/
- (NSError*)save;
/**
* Deletes the object from the managed object context
*/
- (void)destroy;
/**
* Sets attributes on the model from the XML document according to the element to property/relationship mappings
*/
- (void)setAttributesFromXML:(Element*)XML;
// TODO: Need helper method on superclass for this... setAttributesFromXML:/setAttributesFromJSON:/setAttributesFromPayload?
@end