设置Ember数据模型的foreignKey

时间:2014-05-04 07:50:39

标签: ember-data

在Ember Data 1的修订版3中,you could set the foreign key

App.Model = DS.Model.extend({
  namingConvention: {
    // LOUD NAMING CONVENTION
    // Changes fooKey to FOOKEY
    keyToJSONKey: function(key) {
      return key.toUpperCase();
    },

    // Determines the name of foreign keys in
    // belongsTo relationships
    foreignKey: function(key) {
      return key.toUpperCase()+"_ID";
    }
  }
});

现在似乎不起作用(目前版本7)。你如何设置外键?

1 个答案:

答案 0 :(得分:0)

您可能正在寻找keyForBelongsTo。见http://emberjs.com/api/data/classes/DS.RESTSerializer.html

App.ApplicationSerializer = DS.RESTSerializer.extend({
  keyForBelongsTo: function(type, name) {
    return this.keyForAttributeName(type, name) + "_id";
  },
});