filter may not be working correctly
chanan opened this issue · comments
Chanan Braunstein commented
I did the following operations:
const item = session.Item.withId(itemId)
const sections = session.Section.filter(section => section.itemType === item.itemType)
sections.toModelArray().forEach(section => {
console.log(section.id)
console.log('items: %O', section.items.toRefArray())
console.log('filter: %O', section.items.filter({ id: item.id }).toRefArray())
}
The log shows the section.id, items array of 0 (expected) and a filter array of 1.
That shouldn't be possible to have an array of of filtered bigger than the array of non filtered items. What is happening is that it is finding an item from another section
Here are my models:
export class Item extends Model { }
Item.modelName = 'Item'
Item.fields = {
id: attr(),
sections: many({
to: 'Section',
relatedName: 'items'
})
}
export class Section extends Model { }
Section.modelName = 'Section'
Section.fields = {
id: attr(),
form: fk('Form', 'sections')
}
//Cut the rest of the models as they are uneeded
Mark Erikson commented
If this is fixed by #142 , can we close it?