Cannot override `foreignKey` for hasMany using `through` setting
- Vorherrschende Sprache
- JavaScript
- Sterne
- 2k
- Forks
- 238
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
As the title suggests
``` javascript
var Tag = schema.define('Tag', {
name: String,
parent_id: Number
}, {
table: 'tags'
});
var Category = schema.define('Category', {
name: String
}, {
table: 'categories'
});
// Intersection Tables
var TagCategory = schema.define('TagCategory', {
tag_id: Number,
category_id: Number
}, {
table: 'tag_categories'
});
// Relations
TagCategory.belongsTo(Tag);
TagCategory.belongsTo(Category);
Tag.belongsTo(Tag, {
as: 'parent',
foreignKey: 'parent_id'
});
Tag.hasMany(Category, {
as: 'categories',
through: TagCategory,
foreignKey: 'tag_id'
})
Category.hasMany(Tag, {
as: 'tags',
through: TagCategory,
foreignKey: 'category_id'
})
```
This results in table schema like this
- tags
- name
- parent_id
- categories
- name
- tag_categories
- tag_id
- category_id
- tagId
- categoryId
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
The issue is about foreignKey naming in a many-to-many through relation in JugglingDB. Look at the relation definitions in the ORM, likely in lib/relation.js or similar. The bug causes extra columns (tagId, categoryId) to be created. Start by examining how through relations are processed and where foreignKey is applied. Run the provided code to see the generated schema, then trace the logic to fix the override.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- databases, javascript, nodejs
- Bereich
- backend, databases
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 45/100