DS.Model.fields

fieldsEmber.Mapstatic

Defined in addon/-private/system/relationships/ext.js:488

A map whose keys are the fields of the model and whose values are strings describing the kind of the field. A model's fields are the union of all of its attributes and relationships.

For example:

app/models/blog.js
import DS from 'ember-data';

export default DS.Model.extend({
  users: DS.hasMany('user'),
  owner: DS.belongsTo('user'),

  posts: DS.hasMany('post'),

  title: DS.attr('string')
});
import Ember from 'ember';
import Blog from 'app/models/blog';

var fields = Ember.get(Blog, 'fields');
fields.forEach(function(kind, field) {
  console.log(field, kind);
});

// prints:
// users, hasMany
// owner, belongsTo
// posts, hasMany
// title, attribute
doc_EmberJs
2016-11-30 16:50:16
Comments
Leave a Comment

Please login to continue.