title: How to retrieve model data for use inside of another model?
body: <p>I'm working with an Ember app that ties into a Rails backend through a Sails.js API, and ran into an issue I can't find any similar examples for.</p>
  
  <p>My Messages model has a <code>sender_id</code> column, which corresponds with the <code>id</code> column in my Users model. There is also a Profile model (belongs to User through <code>user_id</code>) that contains the <code>username</code> column, which is what I'd like to be able to access through the Messages model as 'senderName' (i.e., <code>message.senderName</code>). My models and routes are all hooked up, so I have access to all the data I need and everything displays correctly in the browser aside from my senderName function.</p>
  
  <p>The plan was to look up the Profile object through its <code>user_id</code> (using <code>sender_id</code>) inside of Messages, then pull the <code>username</code> field from there. I've been able to receive Promises back from my Profile query, but from there I'm not sure how/if I can access the actual <code>username</code> field. Is there a way to do this, or am I trying to fit a square peg into a round hole? </p>
  
  <p>I also tried accessing <code>username</code> by looking up the User object first (<code>this.store.find('user')</code>, etc.) and using my Rails associations for <code>user.profile.username</code>, but that didn't work either. </p>
  
  <p><strong>Models:</strong></p>
  
  <pre><code>  App.Message = DS.Model.extend({
      sender_id : DS.attr('number'),
      content : DS.attr('string'),
      senderName: function() {
        var id = this.get('sender_id');
        var profile = this.store.find('profile', {user_id: id}).then(function() {
        console.log(profile);
        // What next? profile.username doesn't work
      })
    }.property('sender_id')
  });
  
  App.Profile = DS.Model.extend({
     user: DS.belongsTo('user', { async: true }),
     username : DS.attr('string'),
     user_id : DS.attr('number')
  });
  
  App.User = DS.Model.extend({
      profile: DS.belongsTo('profile', { async: true }),
      email: DS.attr('string'),
      name: DS.attr('string')
  });
  </code></pre>
  
  <p><strong>Template:</strong> </p>
  
  <pre><code>&lt;script type="text/x-handlebars" data-template-name="messages/index"&gt;
      &lt;div class="small-12 column"&gt;
          {{#each message in model}}
              &lt;p&gt;From: {{message.senderName}}&lt;/p&gt;
              &lt;p&gt;Content: {{message.content}}&lt;/p&gt;
          {{/each}}
      &lt;/div&gt;
  &lt;/script&gt;
  </code></pre>
  
  <p>Here's an example of the promises I'm receiving back in the browser console: </p>
  
  <pre><code>Promise {_id: 93, _label: undefined, _state: undefined, _result: undefined, _subscribers: Array[0]…}
  </code></pre>
  
  <p>Thanks for your help!</p>