exebook
exebook

Reputation: 33920

Why I cannot modify the result object

Why the objects returned by sequelize findAll and the likes cannot be modified like regular objects? I checked if they are frozen or locked, but Object.isFrozen() returns false. Does it use getters instead of real properties (how do I check that?)

So far my only option to modify the results is to do JSON.parse(JSON.strigify(result)) which is OK, but incurs performance price.

Upvotes: 3

Views: 1519

Answers (1)

Ricardo Machado
Ricardo Machado

Reputation: 782

Your instances have getters and setters methods. You can call instance.get('field') or instance.set('field', value).

But If you are trying to dynamically add a new property to your model, you can try to create a property type : DataTypes.VIRTUAL.

DataTypes.VIRTUAL properties are transients, you can use to customize/add properties value that you dont want to be persisted to database.

http://docs.sequelizejs.com/en/v3/api/datatypes/#virtual

Upvotes: 5

Related Questions