1602 / 1602/jugglingdb

Cannot override `foreignKey` for hasMany using `through` setting

Aperta
#346 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
JavaScript
Stelle
2k
Fork
238
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
databases, javascript, nodejs
Ambito
backend, databases
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.