JeremyV
December 10, 2021, 11:30am
1
In my collection, I have a reference field which is a smart field, called title :
this title smart field is pretty straight forward :
{
field: 'title',
type: 'String',
get: place => `${place.sergicIdFull} - ${place.displayName}`,
search: (query, search) => {
const split = search.split(' ');
const searchCondition = {
[Op.or]: [
{ 'sergic_id_full': { [Op.iLike]: `%${split[0]}%` } },
{ 'sergic_id_full': { [Op.iLike]: `%${split[1]}%` } },
{ 'display_name': { [Op.iLike]: `%${split[0]}%` } },
{ 'display_name': { [Op.iLike]: `%${split[1]}%` } },
],
};
query.where[Op.and][0][Op.or].push(searchCondition);
return query;
}
}
and BTW, in my places model :
const Places = sequelize.define('places', {
displayName: {
type: DataTypes.STRING,
defaultValue: "",
allowNull: false,
},
...
sergicIdFull: {
type: DataTypes.STRING,
},
When I Edit any record, after having clicked Save, I get the following message:
So I changed my reference field to another one:
And it’s now displayed correctly:
@JeremyV
Thank you for sharing this.
Using the snippets from your message, I cannot reproduce the issue. The update toaster properly display my SmartField value when I set it as reference field.
Could you tell my what version of forest-express-sequelize
(or other forest package) you are using?
Did it stop working? Or is this the first time you are using this field as the reference field?
Maybe you could try to reproduce the issue with another SmartField in another collection?
Thank you
JeremyV
December 10, 2021, 3:09pm
3
“forest-express-sequelize”: “^7.12.3”
I have the feeling that it was working before but I’m not 100% sure.
I’ll try that.
Thank you for the details @JeremyV ,
I changed my project to use version 7.12.3, still working on my end.
For the record, here is my model file models/item.js
:
module.exports = (sequelize, DataTypes) => {
const { Sequelize } = sequelize;
const Item = sequelize.define('item', {
value: {
type: DataTypes.STRING,
},
name: {
type: DataTypes.STRING,
},
type: {
type: DataTypes.STRING,
},
}, {
tableName: 'item',
timestamps: false,
schema: process.env.DATABASE_SCHEMA,
});
return Item;
};
and my SmartField definition forest/item.js
:
const { collection } = require('forest-express-sequelize');
collection('item', {
actions: [],
fields: [{
field: 'smart',
type: 'String',
get: item => `${item.value} - ${item.name}`,
search: (query, search) => {
const split = search.split(' ');
const searchCondition = {
[Op.or]: [
{ 'value': { [Op.iLike]: `%${split[0]}%` } },
{ 'name': { [Op.iLike]: `%${split[1]}%` } },
],
};
query.where[Op.and][0][Op.or].push(searchCondition);
return query;
}
}],
segments: [],
});