我们正在使用ember 1.13.5
,ember-data 1.13.7
和sails 0.11
作为后端。
完整错误是:Cannot read property 'modelName' of undefined at ember$data$lib$system$store$$Service.extend.serializerFor
我通过开发工具跟踪代码,然后看到下图所示的代码。它表明modelName
已定义。
这是我setup.js
控制器中调用的实际代码:
_this.store.query('business-account', {user: user.get('id')})
.then(function(businessAccount) {
debugger;
}, function(err) {
debugger;
});
以上引发了以下错误:
TypeError: Cannot read property 'modelName' of undefined
at ember$data$lib$system$store$$Service.extend.serializerFor (https://192.168.10.10:4200/assets/vendor-844725f1b0311e7dd3df737ef28a9edc.js:83513:35)
at https://192.168.10.10:4200/assets/vendor-844725f1b0311e7dd3df737ef28a9edc.js:106657:34
at https://192.168.10.10:4200/assets/vendor-844725f1b0311e7dd3df737ef28a9edc.js:86465:20
at Map.forEach.cb (https://192.168.10.10:4200/assets/vendor-844725f1b0311e7dd3df737ef28a9edc.js:27626:11)
at OrderedSet.forEach (https://192.168.10.10:4200/assets/vendor-844725f1b0311e7dd3df737ef28a9edc.js:27409:11)
at Map.forEach (https://192.168.10.10:4200/assets/vendor-844725f1b0311e7dd3df737ef28a9edc.js:27630:18)
at Function.ember$data$lib$system$model$$default.reopenClass.eachRelationship (https://192.168.10.10:4200/assets/vendor-844725f1b0311e7dd3df737ef28a9edc.js:86464:83)
at DS.default.RESTSerializer.extend._extractEmbeddedRecords (https://192.168.10.10:4200/assets/vendor-844725f1b0311e7dd3df737ef28a9edc.js:106650:12)
at DS.default.RESTSerializer.extend.normalize (https://192.168.10.10:4200/assets/vendor-844725f1b0311e7dd3df737ef28a9edc.js:106635:19)
at apply (https://192.168.10.10:4200/assets/vendor-844725f1b0311e7dd3df737ef28a9edc.js:32729:18)
更新:
我还有一个名为businessAccount
app/models/business-account.js
import DS from 'ember-data';
export default DS.Model.extend({
/////////////////////////////
// ASSOCIATIONS
/////////////////////////////
business: DS.belongsTo('business', { async: true }),
user: DS.belongsTo('user', { async: true }),
/////////////////////////////
// ATTRIBUTES
/////////////////////////////
active: DS.attr('boolean'),
kind: DS.attr('string'),
ROP: DS.attr('string'),
ssn: DS.attr('string'),
biography: DS.attr('string'),
totalPaidToDate: DS.attr('number'),
phoneNumbers: DS.attr('string'),
oneWordDescriptions: DS.attr('string'),
modesOfTransport: DS.attr('string'),
address: DS.attr('string'),
availabilities: DS.attr('string'),
exclusionTImes: DS.attr('string')
});
business.js
import DS from 'ember-data';
export default DS.Model.extend({
/////////////////////////////
// ASSOCIATIONS
/////////////////////////////
businessAccounts: DS.hasMany('businessAccount', { async: true }),
/////////////////////////////
// ATTRIBUTES
/////////////////////////////
name: DS.attr('string'),
legalBusinessName: DS.attr('string'),
timezone: DS.attr('string'),
emails: DS.attr('string'),
phoneNumbers: DS.attr('string'),
availabilities: DS.attr('string'),
exclusionTimes: DS.attr('string'),
holidays: DS.attr('string'),
address: DS.attr('string')
});
user.js
import DS from 'ember-data';
export default DS.Model.extend({
/////////////////////////////
// ASSOCIATIONS
/////////////////////////////
businessAccounts: DS.hasMany('businessAccount', { async: true }),
/////////////////////////////
// ATTRIBUTES
/////////////////////////////
firstName: DS.attr('string'),
lastName: DS.attr('string'),
email: DS.attr('string'),
phoneNumbers: DS.attr('string'),
secondaryContactInfo: DS.attr('string'),
address: DS.attr('string')
});
来自帆的 json
回复:
[
{
"business": {
"name": "businessName",
"ein": null,
"website": null,
"primaryContact": null,
"bankInformation": null,
"legalBusinessName": null,
"timezone": null,
"emails": null,
"phoneNumbers": null,
"availabilities": null,
"exclusionTimes": null,
"holidays": null,
"address": null,
"archived": false,
"id": 1,
"createdAt": "2015-07-31T11:22:26.000Z",
"updatedAt": "2015-07-31T11:22:26.000Z"
},
"user": {
"firstName": "Monty",
"lastName": "Lennie",
"email": null,
"phoneNumbers": null,
"secondaryContactInfo": null,
"address": null,
"archived": false,
"id": 1,
"createdAt": "2015-07-31T11:22:25.000Z",
"updatedAt": "2015-07-31T11:22:25.000Z",
"auth": 1
},
"status": null,
"kind": null,
"active": false,
"ROP": null,
"ssn": null,
"biography": null,
"totalPaidToDate": null,
"phoneNumbers": null,
"oneWordDescriptions": null,
"modesOfTransport": null,
"address": null,
"availabilities": null,
"exclusionTimes": null,
"archived": false,
"id": 1,
"createdAt": "2015-07-31T11:22:26.000Z",
"updatedAt": "2015-07-31T11:22:26.000Z"
}
]