pull/7/head
parent
e6371d7d48
commit
b7279dfdef
6 changed files with 104 additions and 44 deletions
@ -0,0 +1,12 @@ |
|||||||
|
module.exports = (sequelize, DataTypes) => { |
||||||
|
var Album = sequelize.define('Album', { |
||||||
|
name: DataTypes.STRING, |
||||||
|
}); |
||||||
|
|
||||||
|
Album.associate = function (models) { |
||||||
|
models.Album.belongsToMany(models.Song, { through: "SongAlbums" }) |
||||||
|
models.Album.belongsToMany(models.Artist, { through: "AlbumArtists" }) |
||||||
|
}; |
||||||
|
|
||||||
|
return Album; |
||||||
|
}; |
@ -1,11 +1,12 @@ |
|||||||
module.exports = (sequelize, DataTypes) => { |
module.exports = (sequelize, DataTypes) => { |
||||||
var Artist = sequelize.define('Artist', { |
var Artist = sequelize.define('Artist', { |
||||||
name: DataTypes.STRING, |
name: DataTypes.STRING, |
||||||
}); |
}); |
||||||
|
|
||||||
Artist.associate = function(models) { |
Artist.associate = function (models) { |
||||||
models.Artist.hasMany(models.Song); |
models.Artist.belongsToMany(models.Song, { through: "SongArtists" }); |
||||||
}; |
models.Artist.belongsToMany(models.Album, { through: "AlbumArtists" }) |
||||||
|
|
||||||
return Artist; |
|
||||||
}; |
}; |
||||||
|
|
||||||
|
return Artist; |
||||||
|
}; |
@ -1,13 +1,12 @@ |
|||||||
module.exports = (sequelize, DataTypes) => { |
module.exports = (sequelize, DataTypes) => { |
||||||
var Song = sequelize.define('Song', { |
var Song = sequelize.define('Song', { |
||||||
title: DataTypes.STRING, |
title: DataTypes.STRING, |
||||||
}); |
}); |
||||||
|
|
||||||
Song.associate = function(models) { |
Song.associate = function (models) { |
||||||
models.Song.belongsTo(models.Artist, { |
models.Song.belongsToMany(models.Artist, { through: "SongArtists" }); |
||||||
onDelete: "CASCADE" |
models.Song.belongsToMany(models.Album, { through: "SongAlbums" }); |
||||||
}); |
|
||||||
}; |
|
||||||
|
|
||||||
return Song; |
|
||||||
}; |
}; |
||||||
|
|
||||||
|
return Song; |
||||||
|
}; |
Loading…
Reference in new issue