# Model propertery call another model

**URL:** <https://discuss.emberjs.com/t/model-propertery-call-another-model/10176>\
**Category:** Ember Data\
**Created:** [March 16, 2016, 9:53pm UTC](https://discuss.emberjs.com/t/model-propertery-call-another-model/10176 "2016-03-16T21:53:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrock2004](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jrock2004/32/12133_2.png) [@jrock2004](https://discuss.emberjs.com/u/jrock2004)\
**Post date:** [March 16, 2016, 9:53pm UTC](https://discuss.emberjs.com/t/model-propertery-call-another-model/10176/1 "2016-03-16T21:53:50Z")

</div>

Ok so I have the follow API response and I am trying to build an appropriate model for it.

Mirage

```auto
{
          type: 'providers',
          id: 2,
          attributes: {
            category: "Handy",
            status: true,
            name: "John's Service",
            address: {
              street: "125 DeKalb Pike",
              city: "King of Prussia",
              state: "PA",
              zipcode: "19406"
            },
            phone: "215-555-5555",
            email: "john@test.com"
          }
        }

```

So I built two models

address

```auto
export default DS.Model.extend({
  street: DS.attr(),
  city: DS.attr(),
  state: DS.attr(),
  zipcode: DS.attr()
});

```

provider

```auto
export default DS.Model.extend({
  category: DS.attr(),
  status: DS.attr(),
  name: DS.attr(),
  address: DS.belongsTo('address'),
  phone: DS.attr(),
  email: DS.attr(),
  addressline: Ember.computed('address', function() {
    return this.get('address.city') + ', ' + this.get('address.state') + ' '
      + this.get('address.zipcode');
  })
});

```

On my view the address property is empty. What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![francesconovy](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/francesconovy/32/9607_2.png) [@francesconovy](https://discuss.emberjs.com/u/francesconovy)\
**Post date:** [March 17, 2016, 12:45am UTC](https://discuss.emberjs.com/t/model-propertery-call-another-model/10176/2 "2016-03-17T00:45:13Z")

</div>

You probably should do this:

```javascript
addressline: Ember.computed('address.city', 'address.state', function() {
    return `${this.get('address.city')}, ${this.get('address.state')} ${this.get('address.zipcode')}`;
  })

```

I updated it to use ES6 template strings, but the important part is to actually depend on the properties on the relationship, not the relationship itself on the computed property.

---

<div class="post-metadata">

**Author:** ![jrock2004](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jrock2004/32/12133_2.png) [@jrock2004](https://discuss.emberjs.com/u/jrock2004)\
**Post date:** [March 17, 2016, 12:48am UTC](https://discuss.emberjs.com/t/model-propertery-call-another-model/10176/3 "2016-03-17T00:48:45Z")

</div>

Thank you for the help. I also had to do this to the model that I pass into the view

```auto
let record = this.store.createRecord('provider');
record.address = this.store.createRecord('address');

return record;

```

---

<div class="post-metadata">

**Author:** ![vikram7](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/vikram7/32/12393_2.png) [@vikram7](https://discuss.emberjs.com/u/vikram7)\
**Post date:** [March 17, 2016, 2:38pm UTC](https://discuss.emberjs.com/t/model-propertery-call-another-model/10176/4 "2016-03-17T14:38:03Z")

</div>

By `view`, do you mean template? Views have been deprecated in Ember.

---

<div class="post-metadata">

**Author:** ![jrock2004](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jrock2004/32/12133_2.png) [@jrock2004](https://discuss.emberjs.com/u/jrock2004)\
**Post date:** [March 17, 2016, 3:09pm UTC](https://discuss.emberjs.com/t/model-propertery-call-another-model/10176/5 "2016-03-17T15:09:50Z")

</div>

Yes, sorry, I meant template
