Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
broofa opened this issue Mar 2, 2017 · 3 comments
Closed

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

broofa opened this issue Mar 2, 2017 · 3 comments

Comments

@broofa
Copy link
Contributor

broofa commented Mar 2, 2017

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

@sushantdhiman
Copy link
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 }

boltosaurus pushed a commit to boltosaurus/sequelize that referenced this issue Mar 14, 2017
fixes issue # 7318 - sequelize#7318
sushantdhiman pushed a commit that referenced this issue Mar 20, 2017
…7382)

* issue # 7318

fixes issue # 7318 - #7318

* test and change log

* formatting

* changed message

* Update changelog.md

* Update removeAttribute.test.js
@sushantdhiman
Copy link
Contributor

Fixed in #7382

mkaufmaner pushed a commit to mkaufmaner/sequelize that referenced this issue Apr 25, 2017
…ze#7318) (sequelize#7382)

* issue # 7318

fixes issue # 7318 - sequelize#7318

* test and change log

* formatting

* changed message

* Update changelog.md

* Update removeAttribute.test.js
@ratulSharker
Copy link

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
Projects
None yet
Development

No branches or pull requests

3 participants