Skip to content

removeAttribute('id') results in undefined: null data value #7318

Closed

Description

@broofa

Removing the id property results in an "undefined" property being set on the dataValues object.

> var Thing = db.sequelize.define('Thing')

> console.log(model.build().dataValues)
{ id: null }

> model.removeAttribute('id')

> console.log(model.build().dataValues)
{ undefined: null }

> model.build().toJSON()
{ undefined: null }

Dialect: mysql
Database version: mysql Ver 14.14 Distrib 5.7.16, for osx10.11 (x86_64) using EditLine wrapper
Sequelize version: 3.30.2

Activity

  1. added
    type: bug
    on Mar 4, 2017
  2. sushantdhiman commented on Mar 4, 2017

    @sushantdhiman
    Contributor

    Its a bug, with very low priority.

    SSCCE

    const Entry = sequelize.define('Entry', {
      description: {
        type: Sequelize.STRING
      },
      value: {
        type: Sequelize.DECIMAL(17, 2),
        allowNull: false
      }
    });
    
    let instance = Entry.build({ description: 'Hello', value: 23 });
    console.log(instance.toJSON());
    
    Entry.removeAttribute('value');
    instance = Entry.build({ description: 'Hello', value: 23 });
    console.log(instance.toJSON());
    
    Entry.removeAttribute('description');
    Entry.removeAttribute('id');
    instance = Entry.build({});
    console.log(instance.toJSON());

    OUTPUT

    { id: null, description: 'Hello', value: 23 }
    { id: null, description: 'Hello' }
    { undefined: null }
  3. added a commit that references this issue on Mar 14, 2017
  4. sushantdhiman commented on Mar 20, 2017

    @sushantdhiman
    Contributor

    Fixed in #7382

  5. ratulSharker commented on Apr 16, 2020

    @ratulSharker

    I'm still facing this issue. Removed id using Model.removeAttribute(id), then including hasMany association causes null values to appear.

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