Summary
I have a bit of a problem using Ember-Model, trying to establish a unique relationship between two models.
Based on current responses that I have received here on S.O., Ember Forums, and #emberjs. I am beginning to believe that there is no built-in solution for this problem, and I am reformatting my question to specify what is needed.
Details
I am populating a template currently with a full set of debtor information. All the information comes from multiple calls to the server.
The first bit is the basic Debtor info. This part is easy because I can use the model hook and a dynamic segment to retrieve it.
My server returns a JSON for a Debtor… Here’s the short version:
{
"debtor" = {
"debtor_id": 1003,
"debtor_name": Steve,
//... more JSON
"debtor_contact_id": 1345
}
}
The dynamic segment for Debtor is filled with the value of the debtor_id
, but also notice this debtor has a debtor_contact_id
. Every Debtor record retrieved from the server has a unique debtor_contact_id
. On the database, this value is a “foreign key” that will tell which contact table belongs to which debtor table.
There is no way to predict which contact info relates to which debtor without this key/value pair.
I currently have “Contacts” belongsTo
“Debtor”, but that is not enough to do the job.
When it is time to fill the “Contacts” model. Ember-Model needs to know to build the value from debtor_contact_id
into the ajax URL as a query parameter in order to GET the correct API.
I am still learning all of this stuff and so far I have not been able to fully follow any tutorials because my use case has an extra step needed somewhere.
This is the expected behavior I am hoping to see:
- Model hook will work as expected to pull the specific debtor and put it into a “debtor” model (this part is currently working just fine)
- Somehow “debtor_contact_id” is read from the payload
- that value is added as part of a server query to find a separate API
- the resulting contact info will be pulled into a “contact” model
- hopefully a hasMany/belongsTo relationship can be established after both corresponding models are returned.
- all this needs to be done in one big promise before entering my template
I can elaborate more if this does not make sense… thanks!