You are missing a few things here.
1 - You're redefining your client side metadata incorrectly. The correct definition for your 'PriorStudy' entity type should look like this.
name: 'PriorStudy',
dataProperties: {
priorStudyId: { type: breeze.DataType.Int32 },
patientId: { type: breeze.DataType.Int32 },
priorStudyType: { max: 6 },
priorStudyPurpose: { max: 12 },
notes: { max: 250 }
},
navigationProperties: {
patient: 'Patient',
}
Notice the 'patientId' foreign key as well as the 'patient' scalar navigation property.
Then the definition for your 'Patient' entity type can look as follows.
name: 'Patient',
dataProperties: {
patientId: { type: breeze.DataType.Int32 },
firstName: { max: 25 },
lastName: { max: 25 },
},
navigationProperties: {
priorStudies: { entityTypeName: 'PriorStudy', hasMany: true }
}
Notice that you don't specify the 'priorStudies fk' property on the 'Patient' entity type.
2 - When you have defined the metadata correctly, then in your query, you can query your Patient with the 'expand' method to also bring the 'PriorStudies' from the database.
var query = breeze.EntityQuery.from('Patient/1')
.toType('Patient')
.expand('priorStudies');
EDIT 1:
Adding Plunkr
EDIT 2:
In addition to defining (and fixing) the client-side metadata, you also have to write your own custom JsonResultsAdapter. Look for the Edmunds and ESPN samples on the Breeze Samples page. The Breeze mapping json tutorial, may also prove to be helpful.
Here's a gist that I've created to illustrate how to write a custom jsonResultsAdapter
. Look for the createJsonResultsAdapter
method.
Hope this helps.