Ich habe zwei TabellenSequelize hasMany Bezug auf zwei Tabellen
module.exports = function(sequelize , DataTypes){
var order = sequelize.define('prispevok',{
id:{
type: DataTypes.INTEGER,
allowNull:false,
primaryKey:true,
autoIncrement:true
},
Typ:{
type: DataTypes.STRING,
allowNull:false
},
hodnota:{
type: DataTypes.STRING,
allowNull:false
},
popis:{
type: DataTypes.STRING,
allowNull:false
}
})
return order;
}
module.exports = function(sequelize , DataTypes){
var shops = sequelize.define('sponzor',{
id: {
type: DataTypes.INTEGER,
allowNull:false,
primaryKey:true,
autoIncrement:true
},
name:{
type:DataTypes.STRING,
allowNull:false
},
address:{
type: DataTypes.STRING,
allowNull:false
},
web:{
type: DataTypes.STRING,
allowNull:false
},
uid:{
type: DataTypes.STRING,
allowNull:false
},
lat:{
type: DataTypes.DOUBLE,
allowNull:true
},
lng:{
type: DataTypes.DOUBLE,
allowNull:true
}
})
return shops
}
zuerst als
db.donation
Sekunden als
db.sponzor.
Ich möchte 1: m-Beziehung erreichen, ein Sponzor kann mehrere Spenden haben.
I
verwendetdb.sponzor.hasMany(db.donation , {as:'donations', foreignKey:'donations'});
aber es innen überprüft sqlitebrowser es Spalte „Spenden“, fügte Tabelle donatio, nicht umgekehrt, sollte es nicht in dieser Spalte hinzufügen in Tabelle sponzor?
Auch wenn es 1: m-Beziehung ist, wie sollte ich weitere Spenden darin hinzufügen? Sollte ich ID übergeben und es wird ein Array erstellen oder wie soll es gemacht werden?
Vielen Dank für Ihre Hilfe!