-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Closed
Labels
good first issueFor issues. An issue that is a good choice for first-time contributors.For issues. An issue that is a good choice for first-time contributors.type: bugDEPRECATED: replace with the "bug" issue typeDEPRECATED: replace with the "bug" issue type
Description
What are you doing?
const Sequelize = require('sequelize')
const sequelize = new Sequelize({
dialect: 'sqlite',
storage: ':memory:'
})
const Album = sequelize.define('User', {
name: Sequelize.TEXT,
attributes: Sequelize.JSON
})
Album.sync().then(() => {
return Album.create({
name: 'Slow Dance Showdown',
attributes: {
artist: 'john smith',
genre: 'rock'
}
})
}).then(album => {
const dataCopy = album.toJSON()
dataCopy.attributes.genre = 'classical'
dataCopy.name = 'Workout Jams'
console.log('Name compare: ' + (dataCopy.name === album.name)) // works properly
console.log('Attributes compare: ' + (dataCopy.attributes === album.attributes)) // does not work properly
})What do you expect to happen?
Using JSON data-type I expect model.get() and model.toJSON() to return a copy of the object.
What is actually happening?
Instead of a copy of the object representing the JSON you get a reference to the same object that the model uses.
Dialect: mysql / postgres / sqlite
Dialect version: various
Database version: various
Sequelize version: master branch
Tested with latest release: Yes
Metadata
Metadata
Assignees
Labels
good first issueFor issues. An issue that is a good choice for first-time contributors.For issues. An issue that is a good choice for first-time contributors.type: bugDEPRECATED: replace with the "bug" issue typeDEPRECATED: replace with the "bug" issue type