in ObjectContext.m I find @ line 269:
- To create an m_association between two entity instances
- @param sourceObject The source object participating the m_association.
- @param targetObject The target object participating the m_association.
- @param entityName The class name of target object.
- This method only supports adding links to relationships with
- multiplicity = * (The source property is Collection).
- (void) addLink:(ODataObject*) aSourceObject sourceProperty:(NSString*) aSourceProperty targetObject:(ODataObject*) aTargetObject
So notice first that the method asks for sourceProperty but in the documentation above says it wants an entityName, which I've discovered is what it actually looks for. In:
-(void) checkRelationForObject:(ODataObject*)sourceObject property:(NSString
)sourceProperty method:(NSString )method
it compares here: if([[[array objectAtIndex:j] objectForKey:@"Type"] isEqualToString:sourceProperty])
but Type is always the name of the entity, not the source's property name.
What this all boils down to for me is that everything is fine if you have an Order with OrderItems that are of type OrderItem, but if you have an Order with someOrderItems of type OrderItem you have to list the "sourceProperty" as "OrderItem"
to pass the check but when it tries to post the link to OrderItems(guid'someguid')/$links/OrderItems (because in SaveResult.m -(void)processObjectLinks:(RelatedEnd *)aRelatedEnd it will append $links/ [Utility getEntityNameFromUrl:uri] which is NOT the source
property name) it will return a 404 because that link doesn't exist.