Skip to content

Self reference on model not being "expanded" #3804

@emhagman

Description

@emhagman

I have a model defined as:

sequelize.define('referral', {
        status: {
            type: DataTypes.ENUM('OPENED', 'INTERESTED'),
            allowNull: false,
            defaultValue: null
        },
        maxReferrals: {
            field: 'max_referrals',
            type: DataTypes.INTEGER,
            allowNull: false,
            defaultValue: null
        },
        properties: {
            type: DataTypes.JSON,
            allowNull: true,
            defaultValue: null
        },
        reward: {
            type: DataTypes.NUMERIC,
            allowNull: true,
            defaultValue: null
        },
        broken: {
            type: DataTypes.BOOLEAN,
            allowNull: false,
            defaultValue: false
        }
    }, {tableName: 'referral', underscored: true, underscoredAll: true});

Later on:
Referral.belongsTo(Referral, {foreignKey: 'referral_id', as: 'referral', constraints: false});

Basically, every referral has referral_id that references another referral. I can see the referral_id field in my result, but I am missing the expanded referral object that the referral references.

I am calling .findAll({ includes: [{all: true, nested: true}]}) so I believe that data should be there. Any thoughts?

All of the other expands work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions