问题
Dears am getting a problem because included join a table throw another table then i include it immediately
The (User) table should return provider name if i access the (User) table through (Provider)
if included the (User) table imdditly that's mean getting the customer name
but i get the below error
ER_NONUNIQ_TABLE: Not unique table/alias: 'Provider.User'
Code :
models.Order.findOne({
        where: {
            id: req.params.id
        },attributes: ['orderStatus','id','serviceId','providerId','orderDescription',"orderScheduledDate",'userLat','userLng','createdAt'],
        include: [
            {
                model: models.Provider,
                attributes: ['id','userId'],
                include : [{
                    model : models.User,
                    attributes: ['firstName','lastName','phoneNumber']
                },{
                    model : models.User,
                    attributes: ['phoneNumber']
                }]
            }
        ]
    })
    回答1:
If you want to include same model twice , you need to assign an alias to the relation-ship/association :
Provider.belongsTo/haveMany/any...(User, {as: 'ProviderUser'}); //<------ HERE
Provider.belongsTo/haveMany/any...(User, {as: 'User'}); //<------ HERE
include: [{
    model: models.Provider,
    attributes: ['id', 'userId'],
    include: [{
        model: models.User,
        as : 'User' //<---------- HERE
        attributes: ['firstName', 'lastName', 'phoneNumber']
    }, {
        model: models.User,
        as : 'ProviderUser' //<---------- HERE
        attributes: ['phoneNumber']
    }]
}]
    来源:https://stackoverflow.com/questions/53491063/sequelize-not-unique-table-alias