Skip to content

Scopes attributes are not merged #4856

@lifenautjoe

Description

@lifenautjoe

Version : 3.13.0
Dialect : mysql

Given

var User = sequelize.define('User', {
    username: {
        type: DataTypes.STRING,
        allowNull: false
    },
    about: {
        type: DataTypes.STRING
    },
    password: {
        type: DataTypes.STRING,
        allowNull: false,
        set: function (val) {
            // Some encrypting logic
        }
    }
}, {
    scopes: {
        'public': {
            attributes: [
                'id',
                'username',
                'about'
            ]
        },
        'private': {
            attributes: [
                'password'
            ]
        }
    }
});

When querying an instance with multiple scopes, scopes attributes do not get merged.
e.g.

User.scope('public','private').findOneById(1).then(function(user){
    console.log(user.about); // Exists, attribute included from public scope
    console.log(user.password); // Undefined, public and private attributes were not merged
});

Metadata

Metadata

Assignees

Labels

type: bugDEPRECATED: replace with the "bug" issue type

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions