Hi Forest guys.
It looks like there’s a problem with calculated fields since you released v6.3.7 and we can see a second problem with smart fields since v6.6.2.
Expected behavior
Fields calculated “on the fly” (with a getter in the field) are expected to show in the summary view (even when a “related data” element is added to the view). And smart fields values are supposed to always show.
Actual behavior
There are two problems.
Problem with fields calculated with a getter (since v6.3.7)
In our sequelize model we have some fields whose value is calculated with a sequelize getter in the field itself. Here is the field definition inside our sequelize model:
providerCommissionsPercentage: {
type: DataTypes.DECIMAL(5, 2),
get() {
// Workaround until sequelize issue #8019 is fixed see https://github.com/sequelize/sequelize/issues/8019#issuecomment-523265759
const value = this.getDataValue('providerCommissionsPercentage')
return value === null ? null : parseFloat(value)
},
field: 'provider_commissions_percentage',
allowNull: false,
},
Let’s say we have a “main” model with a “hasMany” relationship with another “linked” model (which “belongsTo” th main model.
With version 6.3.7, in case of relationships, the instance passed to any smart field of the “main” model when it’s loaded by the elements shown of the “linked” model in the “related data” element in the summary view, contains only the id. So calling this.getDataValue('providerCommissionsPercentage')
in the “main” model creates an unexpected behavior, because the dataValue
of the field is not there any more (there’s only the id in the instance received!!). So, in the Forest front end the values are first shown (when the “main” model is loaded), then they disappear (maybe the values of the main model loaded by the “linked” model elements shown in the “related data” are written to the store of the single page application? They should not! I thin the store update is not prevented when the “main” model data is re-loaded due to the related collections… or something like this…).
The same happens in the v6.3.15, where you don’t re-load at all the smart fields of the “main” model when loading the “linked” elments in the “related data” view item. But I think, maybe, you still write the missing values in the store of the single page application (front end), so the values disappear immediately after loading.
See this video:
With version 6.6.2 the same still happens, but we also have another problem, related to the smart fields.
Problem with smart fields (since v6.6.2)
The smart fields show NaN
instead of their actual value and the previously described problem is still there. In our case, the NaN
value is due to the price widget The problem is that the underlying value is undefined
. In the following picture, the red arrow points to the field that disappears if a related data collection is set in the summary view (see the above video). And the purple arrows point to the NaN
smart fields of the collection.
This is the smart field definition (I evicted almost everything, to be sure to be free from other errors):
const { collection } = require('forest-express-sequelize')
collection('Booking', {
fields: [
{
field: 'netProviderPayoutField',
type: 'Number',
get: () => {
console.log('Here we are!')
return 10 // booking.netProviderPayout
},
},
],
})
More over, I can’t find the Here we are!
string any where in the logs. It looks like the smart field is not called at all.
And I can’t see the same behavior in all collections: in some other collection smart fields show properly. And in some other collections the value of the smart fields is not loaded. Can’t explain why this happens, but the problem came with v6.6.2.
I tried to reduce the interested model to its “minimum” by removing all the fields but the id
, I removed all the relationships in the model and all the smart fields and actions associated to the collection, but I have the same result.
Downgrading to 6.6.1 solves this second problem.