Given your JSON for contacts, the tasks data does not specify a contact. I realize that it is obvious by looking at the data, as the tasks are an attribute of a contact, but when the data is processed, only the "tasks" data is passed to Task.models
- tasks : [{
id: 1,
title: "write up model layer",
due: "2010-10-5"
}]
As you can see, there is no reference to the contact from which it came.
In your fiddle, the reason you are getting undefined is because this.contact is undefined. "this" refers to the task and task has no contact property.
In your example, you can access the contact data from the contact variable directly, but that is only because it happens to be available in that scope:
This is not the cleanest way to do so, but here is an example of manually adding the contact data to each task:
There are probably a few ways to accomplish what you want, but here are two that should probably work.
1. Include the contact data within each task. This is the easiest, but also results in redundant data and more data going over the wire on each request.
2. Overwrite .models for Contact and manually add the contact info to each task