Cannot filter or use scope on Related Data

Hi Forest,

I recently noticed that I am unable to use filters on related data. Incidentally, now that I have switched to v8, related data that has scopes applied also cause the same error. The issue stems from column names being camelCased instead of using underscores. This means I can use filters on a single worded column such as id but not others. Here’s the error log:


It should say “active_at” instead of “activeAt”. How can I fix this? Thank you.

Hello @Arda_Yurdakul,

Thanks for your message :raised_hands:

I have an idea of what the problem could be here.
Can you please tell me on what project this error occurred (its name)?
And share the sharePoints model?

Thanks!

Hi,
The project name is “monta-server-test” in package.json, but we changed it to “Monta Admin Panel” in Forest. I am sharing the chargePoints model here but the issue persists in all tables. I also should mention I am able to filter data with all columns without error in the regular table view. The issue is with related data Thank you.

// This model was generated by Lumber. However, you remain in control of your models.
// Learn how here: Enrich your models - Documentation

module.exports = (sequelize, DataTypes) => {
const { Sequelize } = sequelize;
// This section contains the fields of your model, mapped to your table’s columns.

// Learn more here: Enrich your models - Documentation
const ChargePoints = sequelize.define(‘chargePoints’, {
externalId: {
type: DataTypes.STRING,
field: ‘external_id’,
},
state: {
type: DataTypes.ENUM(‘disconnected’,‘available’,‘busy’, ‘error’, ‘passive’),
defaultValue: “disconnected”,
allowNull: false,
},
name: {
type: DataTypes.STRING,
},
operatorName: {
type: DataTypes.STRING,
field: ‘operator_name’,
},
identifier: {
type: DataTypes.STRING,
allowNull: false,
},
roaming: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false,
field: ‘roaming’,
},
address1: {
type: DataTypes.STRING,
},
address2: {
type: DataTypes.STRING,
},
address3: {
type: DataTypes.STRING,
},
city: {
type: DataTypes.STRING,
},
zip: {
type: DataTypes.STRING,
},
parkingSpot: {
type: DataTypes.STRING,
field: ‘parking_spot’,
},
note: {
type: DataTypes.STRING,
},
visibility: {
type: DataTypes.ENUM(‘public’,‘private’),
allowNull: false,
},
type: {
type: DataTypes.ENUM(‘ac’,‘dc’),
},
maxKw: {
type: DataTypes.DOUBLE,
field: ‘max_kw’,
},
kwhCostType: {
type: DataTypes.ENUM(‘fixed’,‘spot’),
field: ‘kwh_cost_type’,
defaultValue: “fixed”,
allowNull: false,
},
kwhCostFixedPrice: {
type: DataTypes.DOUBLE,
field: ‘kwh_cost_fixed_price’,
},
kwhCostSpotOverheadPercentage: {
type: DataTypes.DOUBLE,
field: ‘kwh_cost_spot_overhead_percentage’,
},
kwhCostSpotOverheadValue: {
type: DataTypes.DOUBLE,
field: ‘kwh_cost_spot_overhead_value’,
},
kwhSalesType: {
type: DataTypes.ENUM(‘fixed’,‘spot’),
field: ‘kwh_sales_type’,
defaultValue: “fixed”,
allowNull: false,
},
kwhSalesFixedPrice: {
type: DataTypes.DOUBLE,
field: ‘kwh_sales_fixed_price’,
},
kwhSalesSpotOverheadPercentage: {
type: DataTypes.DOUBLE,
field: ‘kwh_sales_spot_overhead_percentage’,
},
kwhSalesSpotOverheadValue: {
type: DataTypes.DOUBLE,
field: ‘kwh_sales_spot_overhead_value’,
},
hasCable: {
type: DataTypes.INTEGER,
field: ‘has_cable’,
},
hasAuthTokens: {
type: DataTypes.INTEGER,
field: ‘has_auth_tokens’,
defaultValue: 0,
allowNull: false,
},
chargePointModelCustom: {
type: DataTypes.STRING,
field: ‘charge_point_model_custom’,
},
smartChargeSetting: {
type: DataTypes.ENUM(‘off’,‘optional’,‘forced’,‘forced-setting’),
field: ‘smart_charge_setting’,
allowNull: false,
},
smartChargePriorityPrice: {
type: DataTypes.INTEGER,
field: ‘smart_charge_priority_price’,
defaultValue: 0,
allowNull: false,
},
smartChargePriorityCo2: {
type: DataTypes.INTEGER,
field: ‘smart_charge_priority_co2’,
defaultValue: 0,
allowNull: false,
},
smartChargePriorityRenewable: {
type: DataTypes.INTEGER,
field: ‘smart_charge_priority_renewable’,
defaultValue: 0,
allowNull: false,
},
activeAt: {
type: DataTypes.DATE,
field: ‘active_at’,
},
chatActiveAt: {
type: DataTypes.DATE,
field: ‘chat_active_at’,
},
autoMovedToGroup: {
type: DataTypes.INTEGER,
field: ‘auto_moved_to_group’,
defaultValue: 0,
allowNull: false,
},
autoStart: {
type: DataTypes.ENUM(‘off’,‘instant-start’,‘instant-schedule’,‘request-start’,‘request-schedule’),
field: ‘auto_start’,
defaultValue: “off”,
allowNull: false,
},
lastActiveAt: {
type: DataTypes.DATE,
field: ‘last_active_at’,
},
integrationActiveAt: {
type: DataTypes.DATE,
field: ‘integration_active_at’,
},
chargingStartedAt: {
type: DataTypes.DATE,
field: ‘charging_started_at’,
},
integrationCount: {
type: DataTypes.INTEGER,
field: ‘integration_count’,
defaultValue: 0,
allowNull: false,
},
staticMapPath: {
type: DataTypes.STRING,
field: ‘static_map_path’,
},
staticMapPathUpdatedAt: {
type: DataTypes.DATE,
field: ‘static_map_path_updated_at’,
},
nextScheduleAt: {
type: DataTypes.DATE,
field: ‘next_schedule_at’,
},
timezone: {
type: DataTypes.STRING,
},
operatorCutPercentage: {
type: DataTypes.DOUBLE,
field: ‘operator_cut_percentage’,
defaultValue: Sequelize.literal(‘0.0000’),
allowNull: false,
},
operatorCutAbsolute: {
type: DataTypes.DOUBLE,
field: ‘operator_cut_absolute’,
allowNull: false,
},
log: {
type: DataTypes.JSON,
allowNull: false,
},
createdAt: {
type: DataTypes.DATE,
field: ‘created_at’,
},
updatedAt: {
type: DataTypes.DATE,
field: ‘updated_at’,
},
deletedAt: {
type: DataTypes.DATE,
field: ‘deleted_at’,
},
location: {
type: DataTypes.BLOB,
field: ‘location’,
},
maxReservationMin: {
type: DataTypes.INTEGER,
field: ‘max_reservation_min’,
allowNull: true,
defaultValue: null,
},
}, {
tableName: ‘charge_points’,
});
// This section contains the relationships for this model. See: Relationships - Documentation.
ChargePoints.associate = (models) => {
ChargePoints.belongsTo(models.chargePointGroups, {
foreignKey: {
name: ‘chargePointGroupIdKey’,
field: ‘charge_point_group_id’,
},
as: ‘chargePointGroup’,
});
ChargePoints.belongsTo(models.serverChargePointModels, {
foreignKey: {
name: ‘chargePointModelIdKey’,
field: ‘charge_point_model_id’,
},
as: ‘chargePointModel’,
});
ChargePoints.belongsTo(models.countryAreas, {
foreignKey: {
name: ‘countryAreaIdKey’,
field: ‘country_area_id’,
},
as: ‘countryArea’,
});
ChargePoints.belongsTo(models.countries, {
foreignKey: {
name: ‘countryIdKey’,
field: ‘country_id’,
},
as: ‘country’,
});
ChargePoints.belongsTo(models.currencies, {
foreignKey: {
name: ‘currencyIdKey’,
field: ‘currency_id’,
},
as: ‘currency’,
});
ChargePoints.belongsTo(models.operators, {
foreignKey: {
name: ‘operatorIdKey’,
field: ‘operator_id’,
},
as: ‘operator’,
});
ChargePoints.belongsTo(models.teams, {
foreignKey: {
name: ‘teamIdKey’,
field: ‘team_id’,
},
as: ‘team’,
});
ChargePoints.belongsTo(models.users, {
foreignKey: {
name: ‘userIdKey’,
field: ‘user_id’,
},
as: ‘user’,
});
ChargePoints.belongsToMany(models.connectors, {
through: ‘chargePointConnector’,
foreignKey: ‘charge_point_id’,
otherKey: ‘connector_id’,
as: ‘connectorsThroughChargePointConnectors’,
});
ChargePoints.belongsToMany(models.users, {
through: ‘sponsoredChargePointUser’,
foreignKey: ‘sponsored_charge_point_id’,
otherKey: ‘user_id’,
as: ‘usersThroughSponsoredChargePointUsers’,
});
ChargePoints.hasMany(models.chargePointAssets, {
foreignKey: {
name: ‘chargePointIdKey’,
field: ‘charge_point_id’,
},
as: ‘chargePointChargePointAssets’,
});
ChargePoints.hasMany(models.chargePointIntegration, {
foreignKey: {
name: ‘chargePointIdKey’,
field: ‘charge_point_id’,
},
as: ‘chargePointChargePointIntegrations’,
});
ChargePoints.hasMany(models.chargePointReadings, {
foreignKey: {
name: ‘chargePointIdKey’,
field: ‘charge_point_id’,
},
as: ‘chargePointChargePointReadings’,
});
ChargePoints.hasMany(models.chargePointSchedules, {
foreignKey: {
name: ‘chargePointIdKey’,
field: ‘charge_point_id’,
},
as: ‘chargePointChargePointSchedules’,
});
ChargePoints.hasMany(models.charges, {
foreignKey: {
name: ‘chargePointIdKey’,
field: ‘charge_point_id’,
},
as: ‘chargePointCharges’,
});
ChargePoints.hasMany(models.hubjectOperators, {
foreignKey: {
name: ‘chargePointIdKey’,
field: ‘charge_point_id’,
},
as: ‘chargePointHubjectOperators’,
});
ChargePoints.hasMany(models.notificationEventUser, {
foreignKey: {
name: ‘userIdKey’,
field: ‘user_id’,
},
as: ‘userNotificationEventUsers’,
});
ChargePoints.hasMany(models.notifications, {
foreignKey: {
name: ‘userIdKey’,
field: ‘user_id’,
},
as: ‘userNotifications’,
});
ChargePoints.hasMany(models.sponsoredChargePoints, {
foreignKey: {
name: ‘chargePointIdKey’,
field: ‘charge_point_id’,
},
as: ‘chargePointSponsoredChargePoints’,
});
};
return ChargePoints;
};

Hi @Arda_Yurdakul,

Thanks for your prompt response.

I am able to reproduce your issue.
The problem seems to appear at version 7.8 of forest-express-sequelize.

We are going to work asap on a fix, and I let you know when it will be done.
Meanwhile, if this is a big pain for you, I can only recommend to downgrade to 7.7.

Thanks again for this report :pray:

Hi @adriguy ,

Thank you so much. I assumed you wanted to check if the column definitions had the ‘field’ variable set. That wasn’t the issue unfortunately. This is a real issue for us as we use scopes on many tables. I’m looking forward to the fix :+1:

1 Like

Hello @Arda_Yurdakul

We just released forest-express-sequelize@8.0.9 which includes the fix for this bug.
Hopefully upgrading should resolve your issue.

(Come back to us if you are still having issues!)

2 Likes

Hello again @romaing

Yes the issue is resolved. Thank you so much :100:

1 Like