Skip to content

Association mixins attempt to override attributes on model, causing error #9952

@bkoltai

Description

@bkoltai

What are you doing?

When I have a model that defines a property whose name matches one of the mixin names that would get generated when I add an association to the model, the model definition and association blows up.

module.exports = (sequelize, DataTypes) => {
  const Company = sequelize.define("company", {
    hasLocations: {
      type: DataTypes.BOOLEAN
    }
  })
  Company.associate = models => {
    Company.Locations = Company.hasMany(models.location)
  }
  return Company
}

What do you expect to happen?

I don't want it to blow up and instead want to skip the hasLocations() method mixin definition because it conflicts with the hasLocations prop

What is actually happening?

I get the following error

TypeError: Cannot read property 'hasLocations' of undefined
    at Model.get (<project-root>/node_modules/sequelize/lib/model.js:3305:29)
    at Model.funcs.(anonymous function) (<project-root>/node_modules/sequelize/lib/model.js:1022:25)
    at Object.mixinMethods (<project-root>/node_modules/sequelize/lib/associations/helpers.js:58:13)
    at HasMany.mixin (<project-root>/node_modules/sequelize/lib/associations/has-many.js:155:13)
    at Function.hasMany (<project-root>/node_modules/sequelize/lib/associations/mixin.js:34:17)

Sequelize version: 5.0.0-beta.12
Tested with latest release: Yes (If yes, specify that version)

Metadata

Metadata

Assignees

No one assigned

    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