1602 / 1602/jugglingdb

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

Ouverte
#346 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
JavaScript
Étoiles
2k
Forks
238
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
databases, javascript, nodejs
Domaine
backend, databases
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Clairement spécifiée
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.