                 else {
                     
                     // only add if value is present
-                    if let relationshipValue = managedObject.valueForKey(relationshipName) {
-                        
-                        // get destination collection
-                        
-                        let arrayValue: [NSManagedObject] = {
-                            
-                            if relationshipDescription.ordered {
-                                
-                                let orderedSet =
-                            }
-                            
-                        }()
+                    if let arrayValue = managedObject.arrayValueForToManyRelationship(toManyRelationship: relationshipName) {
                         
                         // only add resources that are visible
                         var resourceIDs = [UInt]()

        // assert that relationship is to-many
        assert(relationship.toMany, "Relationship \(key) on \(self.entity.name) is not to-many")
        
        if relationship.ordered {
            
            let orderedSet = self.valueForKey(key) as NSOrderedSet
            
            return orderedSet.array as [NSManagedObject]
        }
        
        let set = self.valueForKey(key) as NSSet
        
        return set.allObjects  as [NSManagedObject]
    }

            if !relationshipDescription.toMany {
                
                // get destination resource
                if let destinationResource = managedObject.valueForKey(relationshipName) as? NSManagedObject {
                    
                    // get resource ID
                    let destinationResourceID = destinationResource.valueForKey(self.resourceIDAttributeName) as UInt
                    
                    // add to JSON object
                    jsonObject[relationshipName] = destinationResourceID
                }
            }
            
            // to-many relationship
            else {
                
                if let arrayValue = managedObject.arrayValueForToManyRelationship(toManyRelationship: relationshipName) {
                    
                    // get resource IDs
                    var resourceIDs = [UInt]()
                    
                    for destinationResource in arrayValue {
                        
                        let destinationResourceID = destinationResource.valueForKey(self.resourceIDAttributeName) as UInt
                        
                        resourceIDs.append(destinationResourceID)
                    }
                    
                    // add to jsonObject
                    jsonObject[relationshipName] = resourceIDs
                }
            }
        }
        
