2014-11-17 6 views
0

Ember 데이터 약속 및 그 이상의 관계가 없어졌습니다. 여기에 내가 가진 무엇 :Ember : async hasMany 관계 문제

App.ApplicationRoute = Ember.Route.extend({ 
    model: function() { 
    return Em.RSVP.hash({ 
     tarifs: this.store.find('tarif'), 
     reservations: this.store.find('reservation') 
    }); 
    } 
}); 

그런 다음, tarifsreservationsspectacles에 묶여 있습니다 :

App.SpectaclesRoute = Ember.Route.extend({ 
    isLoaded:false, 

    model: function() { 
     if(this.isLoaded) { 
      return this.store.all('spectacle'); 
     } 

     this.isLoaded = true; 
     return this.store.find('spectacle'); 
    } 
}); 

Spectacles가 반환됩니다

tarifs 및 예약이 모두 응용 프로그램 시작시 (성공)로드 representations ID 배열과 tarifs ID 배열이있는 서버에 의해 생성됩니다. Representations 개체는 아래의 동일한 응답으로 반환됩니다. Tarifs은 첫 번째 호출 덕분에 이미 상점에 있습니다.

다음은 안경 모델의 :

App.Spectacle = DS.Model.extend({ 
    titre: DS.attr('string'), 
    sousTitre: DS.attr('string'), 
    visuelUrl: DS.attr('string'), 
    tarifs: DS.hasMany('tarif', { async: true }), 
    representations: DS.hasMany('representation', { async: true }) 
}); 

문제는 다음과 같습니다 (spectaclesrepresentations가있는 동안) 내가 볼 수있는합니다 (엠버 브라우저 플러그인)에서, spectaclestarifs가 연결되어 있지 않습니다. 내가 찾을 수있는 유일한 차이점은 두 개의 별도 서버 호출로로드된다는 점이지만 문제가되어서는 안됩니다. 맞습니까?

비동기/약속 문제 일 수 있다고 생각했습니다. 나의 필요는 표현에서 첫 번째 스펙타클의 tarif를 얻는 것입니다. 요약하면 : myRepresentation.spectacle.tarifs [0]. 내가 좋아하는 여러 가지 시도 :

representation.get('spectacle.tarifs').then(function(tarifs) { 
    var tarif = tarifs.get('firstObject'); 
    console.log(tarif); 
} 

아무것도 작동하지 않습니다 : tarif는 항상 null입니다. 모든 레코드가로드 된 것으로 보이지만 spectacletarifs 사이의 관계는로드되지 않습니다.

내가 잘못 했나요?

답변

0

OK, 그것을 잊지 문제는 tarif 모델이었다하십시오 tarif 많은 spectacles에 링크 될 수 있기 때문에

App.Tarif = DS.Model.extend({ 
    nom: DS.attr('string'), 
    montant: DS.attr('number'), 
    spectacle: DS.belongsTo('spectacle', { async: true }) 
}); 

은 "belongsTo를"관계, 실수입니다. 방금이 줄을 제거했고 모든 것이 이제 괜찮습니다.

관련 문제