I'm trying to add a custom property to an Ember Data Model. Specifically I want to add a property which defines the REST end point to use in an Ember Data Adapter I'm writing.
My Model is defined as such (with custom property 'endPoint'):
import DS from 'ember-data';
export default DS.Model.extend({
partner_id : DS.attr('string'),
partner_key : DS.attr('string'),
partner_name : DS.attr('string'),
created : DS.attr('string'),
status : DS.attr('string'),
type : DS.attr('string'),
endPoint : 'api_entry'
});
In my Adapter I'm trying to access the property as follows:
_buildURL: function (modelName, store, id, snapshot, requestType, query) {
var host, namespace, url;
var model = store.modelFor(modelName);
var endPoint = model.endPoint;
var endPoint2 = Ember.get(model, 'endPoint');
console.log(endPoint, endPoint2);
host = Ember.get(this, "host");
namespace = Ember.get(this, "namespace");
url = [];
if (host) {
url.push(host);
}
if (namespace) {
url.push(namespace);
}
url.push(modelName);
url = url.join("/");
if (!host) {
url = "/" + url;
}
return url;
},
In the console.log above, both endPoint and endPoint2 are undefined. I'm new to Ember and Javascript. What am I doing wrong? Is there a more 'Ember' way to do this? I don't want to use the actual REST endpoint names as my model names as they do not adhere to Ember model naming conventions.
Help much appreciated.
Aucun commentaire:
Enregistrer un commentaire