1
和的NodeJS我的hasMany有一個模型,其中「匹配」有很多「MatchRoundTypes」Sequelize使用UUID錯誤
匹配具有UUID的主鍵 matchRoundTypes引用與matchesUUID的匹配,而它的列名。
當我嘗試做匹配的發現,包括MatchRoundTypes我得到:
DEBUG:錯誤:MatchRoundTypes沒有關聯到匹配!
我的查詢是這樣的:
Matches.findAll({where: ["isPublished = ?", true], include: [MatchRoundTypes]})
我已經發布之前,這一切以下命令:
Matches.hasMany(MatchRoundTypes, { as: 'roundMaps', foreignKey: 'matchUUID', useJunctionTable: false})
我曾嘗試在聲明的hasMany ...包括外鍵和許多變化不是等
這是我的配對模型:
sequelize.define('Matches', {
uuid: {type: Seq.STRING(36), allowNull: false, primaryKey: true},
name: {type: Seq.STRING(64), allowNull: false},
}, {tableName: 'match', freezeTableName: true})
這裏是我的MatchRoundTypes型號:
sequelize.define('MatchRoundTypes', {
{
uuid: {type: Seq.STRING(36), allowNull: false, primaryKey: true},
roundTypeUUID: {type: Seq.STRING(36), allowNull: false},
roundName: {type: Seq.STRING(64), allowNull: true},
matchUUID: {
type: Seq.STRING(36),
references: "match",
referencesKey: "uuid",
allowNull: false
}
}, {tableName: 'matchRoundTypes', freezeTableName: true})
任何見解是最歡迎的。
對不起,這只是一個剪切和粘貼錯誤...我爲了清楚起見,縮短了表格的名稱,並錯過了一個...將在另一個筆記上編輯並修復 – Marc
...我的表格被賦予了另一個名字......在我使用續集的時候還沒有重要但是obj聲明設置:tableName:'match',freezeTableName:true ...類似於MatchRoundTypes。 – Marc
重要的是'as'。當你在hasMany關聯中定義時,你也必須在加載時進行定義。 –