How to filter collection data

I have two models, itemBlockModel and previousItemBlockModel, and I want to create a collection of previousItemBlockModels that share the same ID as the itemBlockModel.

enyo.kind({
name: "itemBlockModel",
kind: "enyo.Model",

attributes: {
BLNBIOMEDEVENT: {},
BLNSENTINELEVENT: {},
itemId: {remoteKey: "INTITEMID"},
complicationsCollection: {
relation:enyo.toMany({autoFetch: true,
inCommit: false,
inverseKey: "previousItemId",
relationKey: "itemId", //
collection: "previousItemBlockCollection",
isOwner: true})},
listingOrder: {remoteKey: "INTITEMLISTINGORDER"},
description: {remoteKey: "STRITEMDESC"},
label: {remoteKey: "STRITEMNAME"},
},
defaults: {
newNotes: ""
},
constructor: {
create: function(){
this.inherited(arguments);
},
didFetch: function(options, result){
this.inherited(arguments);
this.complicationsCollection.fetchAndReplace({url:this.complicationsCollection.urlReal});
}
Right now I'm using the relation: enyo.toMany() to create a collection of Models whose previousItemId matches up with the itemId. It seems as if it's not autoFetching the models, so I used fetchAndReplace; however, it seems like each instance of the itemBlockModel is getting an unfiltered collection (i.e., ALL the previousBlockItemModels rather than just the ones with matching IDs). What am I doing wrong? I'm including previousBlockItemModel and previousItemBlockCollection below, if it helps.

enyo.kind({
name: "previousItemBlockModel",
kind: "enyo.Model",

attributes:{
previousItemId: {remoteKey: "INTITEMID"},
notesArray: {remoteKey: "STREXPLANATION"},
},
defaults:{
checked: "false"
},
constructor: function(){
this.inherited(arguments);
},
didFetch: function(options, result){
this.inherited(arguments);
}
});

enyo.kind({
name:"previousItemBlockCollection",
kind:"Collection",
model:"previousItemBlockModel",

published:{
previousItemId: ""
},

urlReal: "/ICP/mock/ears.GetPostOpInfoForCase.json",
constructor: function(){
this.inherited(arguments);
},
didFetch: function(options, result){
result = result["ARRCOMPLLIST"];
if (this.previousItemId){

}
this.inherited(arguments);
}
});

Comments

  • edited August 2013
    From your question, I assume that there is no complicationsCollection JSON information in the response for the original call, hence there wont be any conversion of JSON into previousItemBlockModel data.

    Additionally, the collection will return all the previousItemBlockModels as it probably resolves into a 'GET' to an endpoint like /PreviousItemBlockModel/ which in a RESTful type service would return all models. If this endpoint takes additional query parameters (e.g. ?itemId=nn), then you should add that to your URL.

    I suspect also that this.previousItemId, will not pick up the 'published' previousItemId, as that has been supersceded with this.get("previousItemId").
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Twitter