Skip to content

add ability to easily filter the results of findDescendantModels #2058

Description

@moloko

With adaptModel.findDescendants, if you wanted to do something like get all available, mandatory components for a contentObject, you could do this:

Adapt.findById('co-05').findDescendants('components').where({'_isAvailable': true, '_isOptional': false});

However, following #1616 this function is deprecated in favour of findDescendantModels - but as this function returns an Array rather than a Backbone Collection it's necessary to do the following to achieve the same result:

_.filter(Adapt.findById('co-05').findDescendantModels('components'), function(comp) {
    return comp.get('_isAvailable') === true && comp.get('_isOptional') === false;
});

Which is obviously quite a bit wordier compared to the original.

I think it would therefore be useful to amend findDescendantModels to have an optional 2nd parameter filterBy that would give us similar functionality to the original version.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions