不要怂,就是干,撸起袖子干!

associations8.ejs 488 Bytes
// Sequelize instantiation...
var Person = sequelize.define('person', { name: Sequelize.STRING })
var Pet = sequelize.define('pet', { name: Sequelize.STRING })
Person.hasManyAndBelongsTo('pets', Pet, 'owner')
// Table synchronization...
var person  = new Person({ name: 'Luke' }),
    pet1    = new Pet({ name: 'Bob' }),
    pet2    = new Pet({ name: 'Aaron' })
// Save the objects and associate them...
person.fetchAssociations(function(assocs) {
  // assocs == { pets: [pet1, pet2] }
})