2016-12-15 4 views
0

v3.rc5 JS-データ-HTTP rc.2ストアがネストされたオブジェクトをキャッシュしません

  • 私のAPIは、例えば/userは、ネストされたプロファイルで応答し、ネストされたリソースで応答します。

  • "プロファイル" と "ユーザー" は、それぞれの関係を持つ2つのマッパ

"user": { "id": 1, "name": "Peter", "profile": { "id": 5 "dob": "today" } }

"プロファイル" はキャッシュに追加されませんされています。私はuser.profileを呼び出すことができますが、store.cachedFind('profile', 5)戻りは不定。

store.addToCache('profile', user.profile) を呼び出してもエラーは発生しませんが、キャッシュに追加されません。

私は間違っていますか?助けてください。ありがとう。ここで

答えて

1

は、実施例(キーがuserprofileとの間の関係を定義している)です。

import { DataStore } from 'js-data'; 

const store = new DataStore(); 

store.defineMapper('user', { 
    relations: { 
    hasOne: { 
     profile: { 
     foreignKey: 'userId', 
     localField: 'profile' 
     } 
    } 
    } 
}); 

store.defineMapper('profile', { 
    relations: { 
    belongsTo: { 
     user: { 
     foreignKey: 'userId', 
     localField: 'user' 
     } 
    } 
    } 
}); 

const user = store.add('user', { 
    id: 123, 
    profile: { 
    id: 345, 
    userId: 123 
    } 
}); 

console.log(store.get('user', 123)); 
console.log(store.get('profile', 345)); 
console.log(user.profile === store.get('profile', 345)); 
関連する問題