const User = require('../models/User');
const Friend = require('../models/Friend');
const MessageRoom = require('../models/MessageRoom');
const Message = require('../models/Message');
const MessageStatus = require('../models/MessageStatus');

User.sync({force: true})
    .then(function () {
        Friend.belongsTo(User, {as: "from", foreignKey: "userId"});
        Friend.belongsTo(User, {as: "to", foreignKey: "toUserId"});
        User.hasMany(Friend, {as: "friends", foreignKey: "userId"});
        return MessageRoom.sync({force: true});
    })
    .then(function () {
        Friend.belongsTo(MessageRoom, {as: "messageRoom", foreignKey: "messageRoomId"});
        MessageRoom.hasMany(Friend, {as: "friends", foreignKey: "messageRoomId"});
        return Friend.sync({force: true});
    })
    .then(function () {
        Message.belongsTo(MessageRoom, {as: "messageRoom", foreignKey: "messageRoomId"});
        MessageRoom.hasMany(Message, {as: "messages", foreignKey: "messageRoomId"});
        Message.belongsTo(User,{as: "user", foreignKey: "userId"});
        Message.sync({force: true});
    })
    .then(function () {
        MessageStatus.belongsTo(User,{as: "user", foreignKey: "userId"});
        User.hasMany(MessageStatus,{as: "messageStatuses", foreignKey: "userId"});
        MessageStatus.belongsTo(User,{as: "from", foreignKey: "fromUserId"});
        MessageStatus.belongsTo(MessageRoom,{as: "in", foreignKey: "inMessageRoomId"});
        MessageStatus.sync({force: true});
    })
;
module.exports = {
    User,
    Friend,
    MessageRoom,
    Message,
    MessageStatus
};


@@ -250,23 +250,10 @@
 ync(
-%7Bforce: true%7D
 )%0A
+
     
@@ -505,37 +505,24 @@
 geRoom.sync(
-%7Bforce: true%7D
 );%0A    %7D)%0A  
@@ -738,37 +738,24 @@
 Friend.sync(
-%7Bforce: true%7D
 );%0A    %7D)%0A  
@@ -1036,37 +1036,24 @@
 essage.sync(
-%7Bforce: true%7D
 );%0A    %7D)%0A  
@@ -1389,32 +1389,32 @@
 ssageRoomId%22%7D);%0A
+
         MessageS
@@ -1428,21 +1428,8 @@
 ync(
-%7Bforce: true%7D
 );%0A 

update online status