Skip to content

Commit 250bc38

Browse files
committed
Add ability to map different type relationship objects for property
1 parent 14437a6 commit 250bc38

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Classes/JSONAPIResourceParser.m

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ + (void)set:(NSObject <JSONAPIResource> *)resource withDictionary:dictionary {
203203
[resource setValue:[JSONAPIResourceParser jsonAPILink:value] forKey:key];
204204
}
205205

206+
} else if (relationships[key]) {
207+
if (relationships) {
208+
id value = relationships[key];
209+
[resource setValue:[JSONAPIResourceParser jsonAPILink:value] forKey:key];
210+
}
206211
} else {
207212
id value = [attributes objectForKey:[property jsonName]];;
208213
if ((id)[NSNull null] == value) {
@@ -270,10 +275,17 @@ + (void)link:(NSObject <JSONAPIResource>*)resource withIncluded:(JSONAPI*)jsonAP
270275
for (NSString *key in properties) {
271276
JSONAPIPropertyDescriptor *propertyDescriptor = [properties objectForKey:key];
272277
id value = [resource valueForKey:key];
273-
id includedValue = included[[[propertyDescriptor.resourceType descriptor] type]];
278+
279+
Class valueClass = nil;
280+
if (propertyDescriptor.resourceType) {
281+
valueClass = propertyDescriptor.resourceType;
282+
} else if ([value conformsToProtocol:@protocol(JSONAPIResource)]) {
283+
valueClass = [value class];
284+
}
285+
id includedValue = included[[[valueClass descriptor] type]];
274286

275287
// ordinary attribute
276-
if (propertyDescriptor.resourceType == nil) {
288+
if (valueClass == nil) {
277289
continue;
278290
// has many
279291
} else if ([value isKindOfClass:[NSArray class]]) {

0 commit comments

Comments
 (0)