

module.exports = function(sequelize, DataTypes) {

	var UserDevice = sequelize.define('UserDevice', {
			type: {
				type: DataTypes.ENUM('IOS', 'ANDROID'),
				defaultValue: 'IOS'
			},
			token: {
				type: DataTypes.STRING,
				allowNull: false
			}
		},
		{
			classMethods: {
				addDevice: function(deviceInfo) {
					UserDevice.find({where: deviceInfo})
						.success(function(device) {
							if(device) {

							}
							else {
								UserDevice.create(deviceInfo);
							}
						});
				}
			},
			associate: function(models){
				UserDevice.belongsTo(models.User);
			}
		}
	);

	return UserDevice;
};

@@ -310,24 +310,120 @@
 viceInfo) %7B%0A
+%09%09%09%09%09var search = %7B%0A%09%09%09%09%09%09type: deviceInfo.type,%0A          %09%09%09%09token: deviceInfo.token,%0A%09%09%09%09%09%7D;%0A
 %09%09%09%09%09UserDev
@@ -439,26 +439,22 @@
 %7Bwhere: 
-deviceInfo
+search
 %7D)%0A%09%09%09%09%09
@@ -506,33 +506,43 @@
 ) %7B%0A
-%0A
 %09%09%09%09%09%09%09
-%7D%0A%09%09%09%09%09%09%09else %7B%0A%09
+%09device.destroy();%0A%09%09%09%09%09%09%09%7D%0A
 %09%09%09%09
@@ -575,25 +575,16 @@
 eInfo);%0A
-%09%09%09%09%09%09%09%7D%0A
 %09%09%09%09%09%09%7D)

Remove duplicated device token for multiple users