Problems in ordering a sub-sub-association - Sequelize

Asked

Viewed 33 times

0

I wanted to order a sub-sub-association by ASC "orderMeta", but for some reason I tried to take a look at the documentation and I can’t, I put part of my code. orderMeta is found in the association "episodies", model origin model: Assetsmetadata

class Asset extends Model {
    static init(sequelize){
        super.init({
            name: DataTypes.STRING,
            frendlyURL: DataTypes.STRING,
            rate: DataTypes.FLOAT,
            year: DataTypes.INTEGER,
            indicativeAge: DataTypes.INTEGER,
            contentType: DataTypes.STRING,
            backgroundBG: DataTypes.STRING,
            pathMovie: DataTypes.STRING,
            pathTrailer: DataTypes.STRING,
            description: DataTypes.STRING,
            duration: DataTypes.STRING,
            authors: DataTypes.STRING

        }, {
            sequelize
        });
    }
    static associate(model){
        this.hasMany(model.AssetsGroup, { foreignKey: 'assetID', as: 'temporadas' });
    }
}

Other Model

class AssetsGroup extends Model {
    static init(sequelize){
        super.init({
            groupName: DataTypes.STRING,
            groupTrailer: DataTypes.STRING,
            assetID: DataTypes.STRING
        }, {
            sequelize,
            tableName: 'assetsgroup'
        })
    }
    static associate(model){
        this.hasMany(model.AssetsMetadata, { foreignKey: 'metaGroup', as: 'episodios' });
    }
}

Other Model

    class AssetsMetadata extends Model {
    static init(sequelize){
        super.init({
            metaContentPath: DataTypes.STRING,
            metaPoster: DataTypes.STRING,
            metaDescription: DataTypes.TEXT,
            metaName: DataTypes.STRING,
            metaGroup: DataTypes.STRING,
            metaDuration: DataTypes.STRING,
            orderMeta: DataTypes.INTEGER
        }, {
            sequelize,
            tableName: 'assetsmetadata'
        });
    }
}

The controller:

        const Asset = require('../models/Assets');
        const AssetsGroup = require('../models/AssetsGroup');
        const AssetsMetadata = require('../models/AssetsMetadata');
        const AssetTypes = require('../models/AssetsTypes');
        const asset = await Asset.findOne({
        where: {
            frendlyURL: url
        },
        include: [
            { association: 'temporadas',
            include: [{
                model: AssetsMetadata, association: 'episodios'
            }]},
        ]
    });

Reply to the comment:

Unfortunately it did not work. Returns the following error:

"Unhandledpromiserejectionwarning: Typeerror: Cannot read Property '_modelAttribute' of Undefined"

  • 1

    You can test if it works? findOne({ order: [ [Asset.associations.AssetsGroup, AssetsGroup.associations.AssetsMetadata, 'orderMeta', 'ASC'] ] });. I didn’t write as an answer because I’m not sure if it’s right, I tried to adapt from documentation

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.