Files
yourpart3/backend/models/associations.js
2024-08-19 12:34:08 +02:00

44 lines
2.2 KiB
JavaScript

import User from './community/user.js';
import UserParam from './community/user_param.js';
import UserParamType from './type/user_param.js';
import UserRightType from './type/user_right.js';
import UserRight from './community/user_right.js';
import SettingsType from './type/settings.js';
import UserParamValue from './type/user_param_value.js';
import InterestType from './type/interest.js';
import InterestTranslationType from './type/interest_translation.js';
import Interest from './community/interest.js';
export default function setupAssociations() {
SettingsType.hasMany(UserParamType, { foreignKey: 'settingsId', as: 'user_param_types' });
UserParamType.belongsTo(SettingsType, { foreignKey: 'settingsId', as: 'settings_type' });
UserParamType.hasMany(UserParam, { foreignKey: 'paramTypeId', as: 'user_params' });
UserParam.belongsTo(UserParamType, { foreignKey: 'paramTypeId', as: 'paramType' });
UserParam.belongsTo(SettingsType, { foreignKey: 'settingsId', as: 'settings' });
UserParam.belongsTo(User, { foreignKey: 'userId', as: 'user' });
UserRight.belongsTo(User, { foreignKey: 'userId' });
UserRight.belongsTo(UserRightType, { foreignKey: 'rightTypeId', as: 'rightType' });
UserRightType.hasMany(UserRight, { foreignKey: 'rightTypeId', as: 'rightType' });
UserParamType.hasMany(UserParamValue, { foreignKey: 'userParamTypeId', as: 'user_param_values' });
UserParamValue.belongsTo(UserParamType, { foreignKey: 'userParamTypeId', as: 'user_param_type' });
InterestType.hasMany(InterestTranslationType, { foreignKey: 'interestsId', as: 'interest_translations' });
InterestTranslationType.belongsTo(InterestType, { foreignKey: 'interestsId', as: 'interest_translations' });
InterestType.hasMany(Interest, { foreignKey: 'userinterestId', as: 'user_interest_type'} );
User.hasMany(Interest, { foreignKey: 'userId', as: 'user_interest' });
Interest.belongsTo(InterestType, { foreignKey: 'userinterestId', as: 'user_interest_type' });
Interest.belongsTo(User, { foreignKey: 'userId', as: 'user_interest' });
InterestTranslationType.belongsTo(UserParamValue, {
foreignKey: 'language',
targetKey: 'id',
as: 'user_param_value'
});
}