mardi 31 mars 2015

Emberjs + ember-data find with param

I'm trying to find a model based on a param like this :



this.store.find('slide', {slideCategory: category});


But it return :



TypeError: Cannot read property 'length' of undefined


I'm running this code from an action in my SlideRoute.


Here is what my Slide model looks like



App.Slide = DS.Model.extend({
title: DS.attr('string'),
note: DS.attr('string'),
slideCategory: DS.belongsTo('slideCategory')
});


And my SlideCategory model



App.SlideCategory = DS.Model.extend({
title: DS.attr('string'),
slides: DS.hasMany('slide', {async:true})
});


It's running with fixtures and here is one record :



{
id: 1,
slideCategory: 1,
title: 'Slide 1',
note: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse eget hendrerit lacus. Donec venenatis sagittis turpis a aliquet. Ut nec ipsum ac sem lobortis ultrices id eu ante. Aenean ut vehicula odio, non imperdiet risus. Aenean mattis diam nec nulla tincidunt, vitae vehicula dui vehicula.',
}


What I'm trying to do is to query all slide from a specific category and then add them to another model, but without this I'm stuck going backward and querying the category and then finding the slides in this category, although this doesn't work neither, I can't seem to be able to get the hasMany items from the category model.


This is what I currently do, but slideCategory.get('slides') doesn't give me the slides like it would work on another regular static property of the model :



this.store.find('slideCategory', category).then(function(slideCategory){
slideCategory.get('slides').then(function(slides){
$.each(slides, function(k,slide){

});
});
}


I'm using ember 1.11 and ember-data 1.0.0-beta.16


Thank you!





Aucun commentaire:

Enregistrer un commentaire