Question: I have two classes 

* Author with attributes id, papers (Paper relationship), ...
* Paper with attributes id, mainAuthor (Author relationship), authors (Author relationship) ...

and want to map some JSON to it

```
"authors": [
    {
        "id": 123,
        "papers": [
            {
                "id": 1,
                "main_author_id": 123,
                ...
            },
            ...
        ]
    },
    ...
]

```

The problem is that the JSON is not structured like 

```
"authors": [
    {
        "id": 123,
        "papers": [
            {
                "id": 1,
                "main_author": {
                    "id": 123
                }
                ...
            },
            ...
        ]
    },
    ...
]

```

so that I could easily map things (note the \*main\_author\* part of both JSON examples). I tried using mapping this value without a key path as explained [here](https://github.com/RestKit/RestKit/wiki/Object-Mapping#mapping-values-without-key-paths):

```
[authorMapping addAttributeMappingToKeyOfRepresentationFromAttribute:@"main_author_id"];
[authorMapping addAttributeMappingsFromDictionary:@{@"(main_author_id)": @"id"}];

```

but I'm getting an error telling me that the keyPath *id* already exists and I may not add a second mapping for this keyPath. I totally understand this error, but I have no idea how to map from \*main\_author\_id\* back to *id*. Changing the data source may be the best solution, but this is unfortunately not possible.

Any suggestion is highly welcome! Thanks!

Answer: 
This is exactly what foreign key mapping is for. It allows you to temporarily store the 'identity' value that you're provided with and then RestKit will find the appropriate object and complete the relationship.
Apart from the Answer @Wain (foreign key mapping) provided, it is also possible to implement a custom serialization (c.f. [RKSerialization](http://restkit.org/api/latest/Protocols/RKSerialization.html)) and modify the objects before mapping takes place. However, the aforementioned method is superior to this (somehow ugly) solution.