Ember JS 3.1 为什么没有加载hasMany关系的ids?

Ember JS 3.1 Why are the ids not loaded with the hasMany relationship?

这是我的版本。

$ ember -v 
ember-cli: 3.1.4
node: 8.10.0
os: linux x64

我正在尝试使用来自有很多关系的 ID 进行搜索。有一个Promise,但是我不知道在哪里等它。

const user = this.get('user');
return user.get('accounts').then((accounts) => {
    console.log(accounts); // Class {canonicalState: Array(0), store: Class, relationship: ManyRelationship, type: ƒ, record: InternalModel, …}
    console.log(accounts.isLoaded); // true
    console.log(accounts.length); // 0
    const ids = accounts.mapBy('id');
    console.log(ids); // <-- Why is this empty?
    return this.store.query('order', { filter: { accounts: ids } });
}

这也没有按预期工作。

const user = this.get('user');
const accountsRef = user.hasMany('accounts'); // HasManyReference {store: Class, internalModel: InternalModel, hasManyRelationship: ManyRelationship, type: "account", parent: RecordReference}
const ids = accountsRef.ids(); // []

同样失败了。

const user = this.get('user');
const promise = new RSVP.Promise((resolve, reject) => {
    return user.get('accounts').then((accounts) => {
        resolve(accounts);
    });

return promise.then((data) => {
    console.log(data); // // Class {canonicalState: Array(0), store: Class, relationship: ManyRelationship, type: ƒ, record: InternalModel, …}
    const ids = accounts.mapBy('id');
    console.log(ids); // []
});

User 上的 has many 关系定义为 accounts: DS.hasMany('account'),反序列化器使用 records

这适用于 Handlebar 模板,并生成我感兴趣的 ID 列表。

{{#each user.accounts as |account|}}
  {{account.id}} - {{account.name}}
{{/each}}

模型挂钩和模板渲染之间发生了什么?我还需要在哪里进行故障排除?

问题不是 Ember 或 Ember 数据。我的 API 没有使用嵌入的记录或协会的 ID 进行响应。检查您的 API 是否符合规格。