Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- module.exports = function(sequelize, DataTypes) {
- var Tweet = sequelize.define('Tweet', {
- tweet: DataTypes.TEXT
- }, {
- classMethods: {
- associate: function(models) {
- // associations can be defined here
- //creating a one-to-many relationship from user->tweets
- models.User.hasMany(models.Tweet, {as: 'tweets'});
- }
- }
- });
- return Tweet;
- };
- 'use strict';
- module.exports = function (sequelize, DataTypes) {
- var User = sequelize.define('User', {
- username: DataTypes.STRING,
- password: DataTypes.STRING
- }, {
- //classMethod guarantees the password provided by the user matches what's in the db
- classMethods: {
- associate: function (models) {
- //associate every tweet to having one author
- models.Tweet.hasOne(models.User, { as: "Author" });
- models.Tweet#setAuthor(anAuthor);
- }
- }
- });
- return User;
- }; //**Note that 'models' contains two objects: 'Tweet' and 'User'**
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement