Skip to content

PabloAlmonte/loopback-component-relation-filter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

loopback-component-relation-filter

Advanced Relation Filter for loopback (3)

By default, Loopback3 does not allow filtering over relations and related models. This component enables said feature by adding query pre-processing which loads the ids of the requested entities in one single query from the database.

Enable/disable extended searching for all models in your component-config.json

{
    "loopback-component-relation-filter": {
        "enabled": true
    }
}

Enable/disable searching for a specific model in your model-config.json (or also in your models definition file):

{
    "YourModel": {
        "options": {
            "relationFilter": {
                "enabled": false
            }
        }
    }
}

The component uses Loopback's where query to create a big sql query against the database. Enable the filtering on your model and nest your where queries. The component supports a majority of the documented operators except near and regexp.

// e.g. load all books having an author which is employed by a certain publisher and is older than
// a certain age
const filter = {
    where: {
        author {
            employer: {
                identifier: 'fancy-publishing'
            },
            age: {
                gt: 20,
            },
        },
    },
};
const books = await Book.find(filter);