Scope on a smart field extracting a json's column attribute
Scope on a smart field extracting a json's column attribute
Implementation
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
const { collection } = require('forest-express-sequelize');
const models = require('../models');
const { Op } = models.objectMapping;
collection('users', {
actions: [],
fields: [
{
field: 'country',
isFilterable: true,
type: 'String',
get: (record) => record.contact.country,
filter({ condition, where }) {
switch (condition.operator) {
case 'equal':
return {
'contact.country': { [Op.eq]: condition.value },
};
// ... And so on with the other operators not_equal, starts_with, etc.
default:
return null;
}
},
},
],
segments: [],
});