2013-12-10 13 views
7

में एसोसिएशन से संबंधित कनेक्शन से रिकॉर्ड प्राप्त करें मैं एम्बर मॉडल से संबंधित रिकॉर्ड कैसे प्राप्त कर सकता हूं? या: वादा ऑब्जेक्ट से रिकॉर्ड कैसे प्राप्त करें?Ember.js

ग्राहक मॉडल

Docket.Customer = DS.Model.extend({ 
    name:  DS.attr('string'), 
    initial:  DS.attr('string'), 
    description: DS.attr('string'), 
    number:  DS.attr('string'), 
    archived: DS.attr('boolean'), 
    projects: DS.hasMany('project',{ async: true }) 
}); 

परियोजना मॉडल

Docket.Project = DS.Model.extend({ 
    name:  DS.attr('string'), 
    description: DS.attr('string'), 
    number:  DS.attr('string'), 
    archived: DS.attr('boolean'), 
    customer: DS.belongsTo('customer', { async: true }) 
}); 

ढूँढें विधि

var project = this.store.find('project', id).then(function(data) { 
    console.log(data.get('customer').toString()); 
}); 

कंसोल आउटपुट

<DS.PromiseObject:ember654> 

JSON उत्तर

{"projects":[ 
    { 
    "id":1, 
    "name":"test", 
    "number":"a310", 
    "description":null, 
    "archived":false, 
    "customer_id":22 
    } 
]}; 

उत्तर

10

पर मिलता है :)

var project = this.store.find('project', id).then(function(data) { 
    data.get('customer').then(function(c){ 
    console.log(c); 
    } 
}); 
+1

फिर एक और का उपयोग ओह लानत! Facepalm। धन्यवाद! – Slevin