File tree Expand file tree Collapse file tree 3 files changed +27
-6
lines changed Expand file tree Collapse file tree 3 files changed +27
-6
lines changed Original file line number Diff line number Diff line change @@ -59,14 +59,27 @@ - (id)objectForKey:(NSString*)key {
59
59
}
60
60
61
61
- (id )resourceForKey : (NSString *)key {
62
- JSONAPIResource *resource;
62
+ if ([key isEqualToString: @" meta" ] == YES || [key isEqualToString: @" linked" ] == YES ) {
63
+ return nil ;
64
+ }
65
+
66
+ NSDictionary *rawResource = [_dictionary objectForKey: key];
67
+ JSONAPIResource *resource = nil ;
68
+ if ([rawResource isKindOfClass: [NSDictionary class ]] == YES ) {
69
+ Class c = [JSONAPIResourceModeler resourceForLinkedType: [JSONAPIResourceLinker linkedType: key]];
70
+ resource = [JSONAPIResource jsonAPIResource: rawResource withLinked: self .linked withClass: c];
71
+ }
63
72
64
- NSArray *resources = [self resourcesForKey: key];
65
- if (resources.count > 0 ) {
66
- return [resources objectAtIndex: 0 ];
73
+ // Fall back to first element in array
74
+ if (resource == nil ) {
75
+ id resources = [self resourcesForKey: key];
76
+ if ([resources isKindOfClass: [NSArray class ]] == YES ) {
77
+ return [resources firstObject ];
78
+ }
67
79
}
68
80
69
81
return resource;
82
+
70
83
}
71
84
72
85
- (NSArray *)resourcesForKey : (NSString *)key {
Original file line number Diff line number Diff line change 21
21
+ (id )jsonAPIResource : (NSDictionary *)dictionary withLinked : (NSDictionary *)linked withClass : (Class )resourceObjectClass ;
22
22
23
23
- (id )initWithDictionary : (NSDictionary *)dict withLinked : (NSDictionary *)linked ;
24
+ - (void )setWithDictionary : (NSDictionary *)dict ;
24
25
25
26
- (id )objectForKey : (NSString *)key ;
26
27
- (id )linkedResourceForKey : (NSString *)key ;
Original file line number Diff line number Diff line change @@ -90,6 +90,15 @@ - (NSDictionary *)mapKeysToProperties {
90
90
return [[NSDictionary alloc ] init ];
91
91
}
92
92
93
+ - (BOOL )setWithResource : (id )otherResource {
94
+ if ([otherResource isKindOfClass: [self class ]] == YES ) {
95
+
96
+ return YES ;
97
+ }
98
+
99
+ return NO ;
100
+ }
101
+
93
102
- (void )setWithDictionary : (NSDictionary *)dict {
94
103
self.__dictionary = dict;
95
104
@@ -148,9 +157,7 @@ - (void)linkLinks:(NSDictionary*)linked {
148
157
// Gets linked objects for the resource
149
158
id linksTo = [self .links objectForKey: linkTypeUnmapped];
150
159
if ([linksTo isKindOfClass: [NSNumber class ]] == YES || [linksTo isKindOfClass: [NSString class ]] == YES ) {
151
-
152
160
JSONAPIResource *linkedResource = [[linked objectForKey: linkType] objectForKey: linksTo];
153
-
154
161
if (linkedResource != nil ) {
155
162
[self .__resourceLinks setObject: linkedResource forKey: linkTypeUnmapped];
156
163
}
You can’t perform that action at this time.
0 commit comments