This should be simple but am struggling. Found the following post to get my query by a slug to work. EmberJS Direct Slug URL Access Not Working
Works like a charm when navigating from a link-to however according to that post, the model returned should be a single record array when accessing directly. Then just return the first object of the array. However my entire store is getting returned. All subcategories. The slug is unique on each record so it should only return one record when queried on that.
Error: Assertion Failed: ArrayProxy expects an Array or Ember.ArrayProxy, but you passed object
Here is my route code:
PlaySection.Router.map(function () {
this.resource("section");
this.resource('subcategory', { path: "/section/:slug" }, function () {
this.resource("record", { path: ":id" });
});
});
App.SectionRoute = Ember.Route.extend({
model: function (params) {
Ember.Logger.warn("Inside section route");
return this.store.find('subcategory'); // gets all subcategories perfectly
},
setupController: function (controller, model) {
this.controller.set('model', model);
this.controllerFor('sectionnav').set('model', model); //set section nav to list of subcats
}
});
App.SubcategoryRoute = Ember.Route.extend({
model: function (params) {
Ember.Logger.warn("Passed Param: " + params.slug);
return this.store.find('subcategory', { slug: params.slug });
},
serialize: function (model) {
//ANOTHER POSSIBLE ISSUE? THIS IS BEING HIT MULTIPLE TIMES....up to 20 when on PREVIOUS route And 13 times when going to this route directly in url address. THere are 5 subcategories total. With many records. Why??
Ember.Logger.warn("Serializing in subcategoryroute");
return { slug: model.get('slug') };
},
setupController: function (controller, model) {
//If the model comes from a link-to helper it will be an object, if it comes from the route it will be an array of one element
//model is the entire store rather than the one record when going to the route directly. WHY??
if (Ember.isArray(model)) {
this.controller.set('model', model.get('firstObject'));
} else {
this.controller.set('model', model);
}
themodel = this.store.find('subcategory');
this.controllerFor('sectionnav').set('model', themodel);
}
});
Here is are the models (included the embedded records in case these are the cause):
App.Subcategory = DS.Model.extend({
name: DS.attr('string'),
categoryname: DS.attr('string'),
categoryid: DS.attr('number'),
slug: DS.attr('string'),
description: DS.attr('string'),
subcategoryid: DS.attr('number'),
records: DS.hasMany('record', { embedded: 'always', async: true })
});
Ember.Inflector.inflector.irregular("subcategory", "subcategories");
App.Record= DS.Model.extend({
name: DS.attr('string'),
comments: DS.hasMany('comment', { embedded: 'always', async: true }),
events: DS.hasMany('event', { embedded: 'always', async: true })
});
App.Comment = DS.Model.extend({
title: DS.attr('string'),
date: DS.attr('string')
});
App.Event = DS.Model.extend({
name: DS.attr('string'),
description: DS.attr('string'),
eventdates: DS.hasMany('eventdate', { embedded: 'always' })
});
App.Eventdate = DS.Model.extend({
eventDate: DS.attr('string'),
startTime: DS.attr('string'),
endTime: DS.attr('string')
});
Thanks in advance for any assistance.
Aucun commentaire:
Enregistrer un commentaire