lundi 12 octobre 2015

Get belongs item inside nested route

I have 2 model contact, address

contact has_many addresses, address belongs to contact

I wrote code router.js

Router.map(function() {
  this.route('contacts', {}, function(){
    this.route('show', { path: '/:contact_id'}, function(){
          this.route('address', { resetNamespace: true });
    });
  });
});

and I add link-to address inside contacts.show

{{#link-to 'address'}}Address{{/link-to}}

problem is set model that find address model with contact_id

access http://localhost:3000/contacts/1

return

{
  "contact": {
    "id": 1,
    addresses": [
    {
    "id": 1,
    "title": "My First Home",
    "location": "ABCD",
    "is_current": false,
    "description": " ASDFASDASD"
    }
  ]
  }
}

How I get address model in address route?

I have already parent routes 'contacts.show'.

import Ember from 'ember';

export default Ember.Route.extend({ 
    model: function () {
        var parentId = this.modelFor('contacts.show').get('id');
        return this.store.findAll('address');
    },
});

I don't know change the line return this.store.findAll('address');




Aucun commentaire:

Enregistrer un commentaire