I am new to Sproutcore and am learning the basics. I'm stuck at the following problem:
I have a model:
Myapp.Space = SC.Record.extend({
id: SC.Record.attr(Number),
name: SC.Record.attr(String),
creator: SC.Record.toOne('Myapp.User', {isMaster: YES, inverse: 'space'})
});
Myapp.User = SC.Record.extend({
id: SC.Record.attr(String),
name: SC.Record.attr(String)
});
And a controller:
Myapp.spaces_controller = SC.ArrayController.create(
{
allowsMultipleSelection: NO,
selection: null,
isEditable: YES
});
In my data source I am doing a remote GET call:
fetch: function(store, query) {
var recordType = query.get('recordType');
var url;
if (recordType === Myapp.Space) {
url = "spaces"
}
SC.Request.getUrl(this.baseApiUrl(store) + url).set('isJSON', YES)
.notify(this, this._didFetch, {
store: store,
recordType: recordType
}).send();
},
_didFetch: function (response, params) {
var store = params.store,
recordType = params.recordType;
if (SC.$ok(response)) {
store.loadRecords(recordType, response.get('body'));
}
},
When I call
Myapp.spaces_controller.set('content', Myapp.store.find(Myapp.Space));
(after login of the user) I get the error:
Uncaught TypeError: Object function (props) {
this.__sc_super__ = ret.prototype;
return this._object_init(props);
} has no method 'storeKeyFor' javascript.js?1377681200:11281
SC.Store.SC.Object.extend.loadRecord javascript.js?1377681200:11281
SC.Store.SC.Object.extend.loadRecords javascript.js?1377681200:11337
Myapp.DataSource.SC.DataSource.extend._didFetch data_source.js?1378388369:39
SC.Response.SC.Object.extend._notifyListeners javascript.js?1377681198:392
SC.Response.SC.Object.extend.notify javascript.js?1377681198:413
(anonymous function) javascript.js?1377681198:314
SC.run javascript.js?1377681203:14741
SC.Response.SC.Object.extend.receive javascript.js?1377681198:298
SC.XHRResponse.SC.Response.extend.finishRequest javascript.js?1377681198:628
SC.mixin.handle javascript.js?1377681199:4249
(anonymous function)
I can access the objects in the response body but the store does not get the data.
I could not find any mentioning of this error online. Can anybody help?
The error of Object function(props) ... has no method 'storeKeyFor'
looks to me like you are attempting to call a function on a Class rather than on an actual Instance of that class.
My first guess is that your recordType is being set as an actual class rather than a string, and that may be causing some issues. In general, I would recommend using 'MyApp.Space'
whenever dealing with record types as that will be evaluated and found at runtime. If it can't find it for some reason, it will throw a slightly nicer message.
Hope this helps!