Skip to content

Nested includes not working with mariadb #10910

Open

Description

@sublime93

What are you doing?

When querying with 2 levels of 'include' no results are returned. This only happens when using the 'mariadb' dialect. First join is a standard 1:N second join in N:N

When running the generated SQL on the DB directly the proper results are returned.

To Reproduce
Steps to reproduce the behavior:

  1. Define models
    PSATicket
PSATicket.belongsTo(PSAContact, { foreignKey: 'contactId', targetKey: 'psaId' });

PSAContact

attributes: {
psaId: { type: Sequelize.DataTypes.INTEGER, allowNull: false },
....
}
PSAContact.belongsToMany(User, { through: UserPSAContact, foreignKey: 'contactId' });

UserPSAContact

attributes: {
userId: { type: Sequelize.DataTypes.INTEGER, allowNull: false, references: { model: 'user', key: 'id' } },
contactId: { type: Sequelize.DataTypes.INTEGER, allowNull: false, references: { model: 'psacontact', key: 'id' } 
}
}

User

User.belongsToMany(PSAContact, { through: UserPSAContact, foreignKey: 'userId' });
  1. Run the following
// code here
let tTest = await SQ.PSATicket.findAll({
            include: [{
                attributes: [],
                model: SQ.PSAContact,
                required: true,
                include: [{
                    nested: true,
                    attributes: [],
                    model: SQ.User
                }]
            }]
        })
  1. See error

What do you expect to happen?

Return all tickets which have a contact and that contact has a user mapped to it.

What is actually happening?

Returning empty array

Environment

Dialect:

  • mariadb
    Dialect library version: 2.0.4
    Database version: 10.3.12-MariaDB
    Sequelize version: 5.8.5
    Node Version: 10.15.1
    OS: Windows 10
    Tested with latest release:
  • No
  • Yes, specify that version: 5.8.5

Activity

  1. knoxcard commented on May 8, 2019

    @knoxcard
    Contributor
  2. added
    dialect: mariadb
    status: understood
    type: bug
    on Aug 1, 2019
  3. github-actions commented on Nov 11, 2021

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

  4. added theissue type on Mar 9, 2025
  5. removed
    type: bug
    on Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    dialect: mariadbstatus: understood

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions