Skip to content
This repository was archived by the owner on Nov 11, 2025. It is now read-only.
This repository was archived by the owner on Nov 11, 2025. It is now read-only.

Properties are not being prevented from being set. #13

@davidbarratt

Description

@davidbarratt

If you call .create() on a model with a field you are not allowed to set, the field will be set and not returned to you (even if you have the role's get set to true).

Example:

const RSVP = sequelize.define('rsvp', {
  id: {
    type: Sequelize.CHAR(26),
    field: 'rsvp_id',
    defaultValue: () => ulid().toLowerCase(),
    primaryKey: true,
    validate: {
      isLowercase: true,
    },
    roles: {
      self: {
        get: true,
        set: false,
      },
    },
  },
});

Doing something like this:

RSVP.create({ id: '1234' }, { role: 'self' });

Results in saving a row with id set to 1234, but then returning an empty object.

This will also fail:

RSVP.build({ id: '1234' }, { role: 'self' }).save()

And this will fail:

(new RSVP({ id: '1234' }, { role: 'self' })).save()

Workaround is to call build, set, and save explicitly.

RSVP.build().set({ id: '1234' }, { role: 'self' }).save()

That will prevent setting the id, but still give you an empty object (since I guess the default doesn't come back through?) so to get around that you have to do this:

RSVP.build().set({ id: '1234' }, { role: 'self' }).save()
  .then(rsvp => rsvp.get({ role: 'self' }))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions