Skip to content

as: {singular, plural} not working with include: {all: true} #9928

@actuallymentor

Description

@actuallymentor

What are you doing?

I am specifying the singular and plural names of an alias. I then later try to include with the all: true option, but that results in a SequelizeDatabaseError of { name: 'SequelizeEagerLoadingError' }.

When I specify an as without explicit singular/plurals this issue does not arise.

Note: I think the issue is similar to what @raxod502 commented here.

let name = 'theAliasName'

// Below works with include: { all: true }
through: db.define( name, {
		amount: Sequelize.FLOAT,
		unit: Sequelize.STRING,
		dataSource: Sequelize.STRING
	} ),
	as: name + 's'
} )

// Below DOES NOT work
through: db.define( name, {
		amount: Sequelize.FLOAT,
		unit: Sequelize.STRING,
		dataSource: Sequelize.STRING
	} ),
	as: {
		singular: name,
		plural: name + 's'
	}
} )

Later these associations are called with:

Model.findOne( {
    where: { id: relevant_id, userId: user_id },
    include: [ { all: true } ]
} ) )

What do you expect to happen?

I expect:

  • The alias table to be populated when a relationship is set (happens in both cases, no issue)
  • The include: { all: true } to load the associated data

What is actually happening?

Sequelize throws { name: 'SequelizeEagerLoadingError' }

Dialect: postgres
Database version: 10.5
Sequelize version: 4.38.1
Tested with latest release: Yes

Edit 1: added code used to findOne
Edit 2: added error name

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