| Module: | @ember-data/model |
|---|
Defined in ../packages/model/addon/-private/model.js:1122
Given a callback, iterates over each of the relationships in the model, invoking the callback with the name of each relationship and its relationship descriptor.
The callback method you provide should have the following signature (all parameters are optional):
function(name, descriptor);
name the name of the current property in the iterationdescriptor the meta object that describes this relationshipThe relationship descriptor argument is an object with the following properties.
Note that in addition to a callback, you can also pass an optional target object that will be set as this on the context.
Example
app/serializers/application.jsimport JSONSerializer from '@ember-data/serializer/json';
export default class ApplicationSerializer extends JSONSerializer {
serialize(record, options) {
let json = {};
record.eachRelationship(function(name, descriptor) {
if (descriptor.kind === 'hasMany') {
let serializedHasManyName = name.toUpperCase() + '_IDS';
json[serializedHasManyName] = record.get(name).map(r => r.id);
}
});
return json;
}
}
© 2022 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember-data/4.9/functions/Model/eachRelationship