2012-10-16 3 views
2

포함 된 개체의 부모 개체에 액세스 할 수있는 방법이 있습니까? 예를 들면 :포함 된 개체의 부모 레코드에 대한 액세스

App.Person = DS.Model.extend({ 
    name : DS.attr('string'), 
    emails : DS.hasMany('App.Email', { embedded: true }) 
}); 

App.Email = DS.Model.extend({ 
    label : DS.attr('string'), 
    email : DS.attr('string'), 

    setParentUpdated: function() { 
     if(this.get('isDirty') == true) 
      // this.get('parent').get('stateManager').goToState('updated'); 
      // I would like to do something like this.get('parent') 
      // to access 'App.Person' instance object 
    }.observes('isDirty') 
}); 

답변

5

이유는 단순히를 셋업 belongsTo 관계를?

App.Email = DS.Model.extend({ 
    person: DS.belongsTo('App.Person') 

    //... 
}); 

그러면 이메일의 person 속성을 사용할 수 있습니다.

+0

감사합니다. mike! 하지만 'App.Email'은 'App.Person'뿐만 아니라 다른 모델에도 포함되어 있기 때문에 할 수 없습니다. – ThomasDurin

+0

릴레이션이 게으르므로 참조 해제 될 때만로드되므로 관계가 문제가되어서는 안됩니다. 그렇지 않은 경우 아무 것도 발생하지 않고 지금 그대로 동작을 유지합니다. –

+0

@ 토마스 모델에 대해 여러 belongsTo 관계를 정의 할 수 있어야합니다. – mehulkar

관련 문제