I have a note model that I want to connect to one of the other two models, customers and suppliers.
In my database, I have a foreignType and foreignId field that contains the type and the corresponding identifier for the customer or supplier, something like
notes: { {id: 1, body:'bar',foreignType:'customer',foreignId:100},
{id: 2, body:'foo',foreignType:'supplier',foreignId:100}
}
That is, a note may be attached to a customer or supplier.
The convention looks like the field is called noteType? I saw a tutorial where the associated type was nested in JSON and not in the root directory.
My ember models are as follows:
export default DS.Model.extend({
body: DS.attr('string'),
foreign: DS.belongsTo('noteable',{polymorphic:true})
});
export default DS.Model.extend({
notes: DS.hasMany('note')
});
import Noteable from '../noteable/model';
export default Noteable.extend({
name: DS.attr('string'),
});
{"customer":{"id":2,"name":"Foobar INC",...},
"contacts":
[{"id":1757,"foreignType": "customer","foreignId":2,...},
{"id":1753,"foreignType": "customer","foreignId":2,...},
...],
...
"todos":
[{"id":1,"foreignType":"customer","foreignId":2,"description":"test todo"}],
"notes":
[{"id":1,"foreignType":"customer","foreignId":2,"body":"Some customer note "}]
}
How to configure this correctly, i.e. what awaits Ember?
My notes do not meet the requirements of the client model. They appear on the Data tab of the Ember Inspector, but the list of notes for any client is empty.
I see several possibilities:
/ DS.Model notes: belongsTo('noteable'), , , - , . , ember (data) .
. , , , ?
, customernote/suppliernote, contactcontact/suppliercontact, //. backend / . , ....
: 2.2.0
Ember Data: 2.2.1