samedi 22 octobre 2016

Ember Data Not Using Irregular Route For Find But Is For CreateRecord

I was wondering would someone be able to help. I am using an irregular route name which seems to be working when calling the createRecord on the store but not on the find.

In the router.js file, I am specifying the route paths as follows:

this.route('admin', function() {
    this.route('staff');
});

// This is so the parent route data does not display in the sub-route
this.route('admin.staff.create-staff', { path: '/admin/staff/create-staff' });

Then in the inflector model file, I am specifying the following irregularities:

inflector.irregular('create-staff', 'staff');

Now in the route, within the model function, I am specifying the following:

model(params) {
    var model = null;

    const id = params.id;
    if(id) {
        model = this.store.find('create-staff', id);            
    } else {
        model = this.store.createRecord('create-staff'); 
    }

    return model;
},

Everything is working when I call the model without any query parameters (i.e. it's calling a GET request to REST API endpoint at ...../staff/). But when I do specify the query parameters, it's not working correctly and not going to the irregular path as specified above (i.e. it's calling a GET request to the REST API at ......./createStaff/{id}).

Would anyone be able to help me with making sure that the 'find' and 'createRecord' are both directed to the irregular 'staff' endpoint on the REST API?

Thanks in advance Graham




Aucun commentaire:

Enregistrer un commentaire