이 여기에서 논의되었습니다 http://discuss.emberjs.com/t/fetching-single-records/529/3
의 ID를 기반으로 단일 레코드를로드와 문제는, 다시 약속으로 DS.Model 개체를 얻을 필요가있다. 이미 클라이언트의 메모리에있는 레코드를 가져 오면 이제 동일한 레코드 (유형 및 ID 조합)를 나타내는 두 개의 다른 오브젝트를 갖게됩니다.
var user123 = App.User.find(123);
var currentUser = App.findByUrl('/users/current'); //This is an imaginary method, i.e. Ember Data don't support it
notEqual(user123, currentUser, "The user objects can't be the same cause we don't know what the current user is yet");
이제 우리는 서버에서이 응답을 얻을 :
{
"user": {
"id": 123,
"name": "Mufasa"
}
}
이제 경우 CurrentUser 및 user123 모두 ID (123)을 가지고 있지만 본질적으로 아주 나쁜 다른 개체 =있는이 예제를 가져 가라. 이것이이 접근법이 효과가없는 이유입니다.
대신 사용자 레코드 배열을로드하고로드하도록 수신 대기 한 다음로드 된 레코드에서 firstObject를 가져와야합니다. 좋아요 :
var users = App.User.find({ is_current: true });
users.one('didLoad', function() {
App.set('currentUser', users.get('firstObject');
});
$.ajax({
type: 'GET',
url: '/users/current',
success: function(payload) {
var store = this.store;
var userReference = store.load(App.User, payload.user);
App.set('currentUser', store.recordForReference(userReference));
}.bind(this)
});