Skip to content

paranoid is not working with underscored option #10565

Closed

Description

@keepcosmos

What are you doing?

Destory instance with paranoid and underscored.
After update deleted_at column(db), sequelize does not map to deletedAt field(instance).

What do you expect to happen?

brand.destory();

brand {
  dataValues:
   { id: '16',
     updatedAt: '2019-03-16T11:01:19.633Z',
     createdAt: '2019-03-16T10:47:23.738Z',
     deletedAt: '2019-03-16T11:01:43.930Z'
   },
  _previousDataValues:
   { id: '16',
     deletedAt: null,
     createdAt: '2019-03-16T10:47:23.738Z',
     updatedAt: '2019-03-16T11:01:19.633Z' }

What is actually happening?

brand {
  dataValues:
   { id: '16',
     updatedAt: '2019-03-16T11:01:19.633Z',
     createdAt: '2019-03-16T10:47:23.738Z',
     deletedAt: null,
     deleted_at: '2019-03-16T11:01:43.930Z'
   },
  _previousDataValues:
   { id: '16',
     deletedAt: null,
     createdAt: '2019-03-16T10:47:23.738Z',
     updatedAt: '2019-03-16T11:01:19.633Z' }

Dialect: postgres
Sequelize version: 5.1.0
Tested with latest release: Yes

Note : Your issue may be ignored OR closed by maintainers if it's not tested against latest version OR does not follow issue template.

Activity

  1. sushantdhiman commented on Mar 18, 2019

    @sushantdhiman
    Contributor

    Seems to work ok

    const Model = sequelize.define('model', {
      name: Sequelize.STRING
    }, {
      paranoid: true,
      timestamps: true,
      underscored: true
    });
    
    sequelize.sync({ force: true }).then(async () => {
      const a = await Model.create({ name: 'abc' });
    
      console.log(a.get());
    
      await a.destroy();
    });
    Executing (default): CREATE TABLE IF NOT EXISTS "models" ("id"   SERIAL , "name" VARCHAR(255), "deleted_at" TIMESTAMP WITH TIME ZONE, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL, "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL, PRIMARY KEY ("id"));
    Executing (default): SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t, pg_class i, pg_index ix, pg_attribute a WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid AND t.relkind = 'r' and t.relname = 'models' GROUP BY i.relname, ix.indexrelid, ix.indisprimary, ix.indisunique, ix.indkey ORDER BY i.relname;
    Executing (default): INSERT INTO "models" ("id","name","created_at","updated_at") VALUES (DEFAULT,$1,$2,$3) RETURNING *;
    { id: 1,
      name: 'abc',
      updatedAt: 2019-03-18T14:45:58.678Z,
      createdAt: 2019-03-18T14:45:58.678Z,
      deletedAt: null }
    Executing (default): UPDATE "models" SET "deleted_at"=$1 WHERE "id" = $2 AND "deleted_at" IS NULL
  2. keepcosmos commented on Mar 18, 2019

    @keepcosmos
    Author

    @sushantdhiman Right, it actually deleted.
    But the point is,
    after deleted, deleted_at column value is not assign to deletedAt property.

    sequelize.sync({ force: true }).then(async () => {
      const a = await Model.create({ name: 'abc' });
      await a.destroy();
      
      console.log(a.deletedAt);
      // => null
     console.log(a.getDataValue('deleted_at'));
     // => '2019-03-18T14:45:58.678Z'
    });

    delete_at is assigned to dataValues

  3. added
    type: bug
    and removed on Mar 18, 2019
  4. malditogeek commented on Mar 26, 2019

    @malditogeek

    Experiencing this as well on 5.1.1

  5. KristenKatona commented on Mar 26, 2019

    @KristenKatona

    My team is also experiencing the issue and we've done a workaround by creating a base model that all of our paranoid delete models extend. In that base model we added a hook for afterDestroy that simply renames the deleted_at field to deletedAt.

  6. papb commented on Aug 20, 2019

    @papb
    Member

    Closing in favor of #11225

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions