Cannot edit created_at

Expected behavior

When editing this ‘created_at’ field, the value should be updated.

Actual behavior

The value is not updated. The new value is not sent in the request to the backend. If other fields are updated at the same time, their value is updated, but not this field.

Context

Please provide any relevant information about your setup.

  • Package Version:
    “forest-express”: “^7.4.0”,
    “forest-express-sequelize”: “^6.6.0”,
  • Express Version: 4.16.3
  • Sequelize Version:
  • Database Dialect: postgresql
  • Database Version:
  • Project Name: bunji-app-forest

Hi @kmcb !
I don’t really understand your issue, can you give me more context please ?

Hi Nicolas,

I have a field named “created_at”. At first it was set as read-only in the front-end (so maybe your application detects this field name and treat it specifically. In the model, this field has a “normal” definition).
I disabled this “read-only” setting so now i can edit it manually with the usual “edit” form.
But the new value is not saved.
I looked at the request sent to the server, and the value sent for this field is the previous one, not the new one i entered.

Ps: i think your team is french, i’m too so we can speak in french, if it may help understanding

Sorry, but we enforce english here so that everyone can benefit from the discussions :slight_smile:
Can you share the model of the collection on which you have the issue ?

yes here it is :

// This model was generated by Lumber. However, you remain in control of your models.
// Learn how here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models
module.exports = (sequelize, DataTypes) => {
  const { Sequelize } = sequelize;
  // This section contains the fields of your model, mapped to your table's columns.
  // Learn more here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
  const Projects = sequelize.define(
    "projects",
    {
      projectType: {
        type: DataTypes.ENUM("buy", "sell"),
        field: "project_type",
        allowNull: false,
      },
      fullAddress: {
        type: DataTypes.STRING,
        field: "full_address",
      },
      address: {
        type: DataTypes.STRING,
      },
      // ... tens of other fields here 
      createdAt: {
        type: DataTypes.DATE,
        field: "created_at",
      },
      updatedAt: {
        type: DataTypes.DATE,
        field: "updated_at",
      },
      deletedAt: {
        type: DataTypes.DATE,
      },
    },
    {
      tableName: "projects",
      schema: process.env.DATABASE_SCHEMA,
    }
  );

  // This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
  Projects.associate = (models) => {
    // ... many associations here 
  };

  return Projects;
};

Can you try to add timestamps: false like so ?

Thanks ! It is now correctly edited. The “updated_at” field is not automatically updated anymore, but this problem should be easier to bypass.

updated_at should be easy to set with a beforeUpdate hook in the model, so this issue can be considered as solved, thanks again

Glad to hear it ! :slight_smile: