Hi !
- PostgreSQL 12.4
- forest-express-sequelize ( “version”: “6.6.3” )
{
"name": "shakai",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node ./server.js"
},
"dependencies": {
"axios": "^0.21.1",
"body-parser": "1.19.0",
"chalk": "~1.1.3",
"cookie-parser": "1.4.4",
"cors": "2.8.5",
"debug": "~4.0.1",
"dotenv": "~6.1.0",
"express": "~4.17.1",
"express-jwt": "5.3.1",
"forest-express-sequelize": "^6.0.0",
"form-data": "^3.0.0",
"morgan": "1.9.1",
"parse-data-uri": "^0.2.0",
"pg": "~8.2.2",
"require-all": "^3.0.0",
"sequelize": "~5.15.1"
}
}
- It happend not only on this particular table.
-
UserHobby:
// This model was generated by Lumber. However, you remain in control of your models.
// Learn how here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models
module.exports = (sequelize, DataTypes) => {
const { Sequelize } = sequelize;
// This section contains the fields of your model, mapped to your table's columns.
// Learn more here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
const UserHobby = sequelize.define('userHobby', {
level: {
type: DataTypes.INTEGER,
allowNull: false,
},
userId: {
type: DataTypes.UUID,
primaryKey: true,
allowNull: false,
},
hobbyId: {
type: DataTypes.INTEGER,
primaryKey: true,
allowNull: false,
},
created: {
type: DataTypes.DATE,
defaultValue: Sequelize.literal('now()'),
allowNull: false,
},
updated: {
type: DataTypes.DATE,
defaultValue: Sequelize.literal('now()'),
allowNull: false,
},
}, {
tableName: 'user_hobby',
timestamps: false,
schema: process.env.DATABASE_SCHEMA,
});
// This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
UserHobby.associate = (models) => {
UserHobby.belongsTo(models.hobby, {
foreignKey: {
name: 'hobbyIdKey',
field: 'hobbyId',
},
as: 'hobby',
});
UserHobby.belongsTo(models.user, {
foreignKey: {
name: 'userIdKey',
field: 'userId',
},
as: 'user',
});
};
return UserHobby;
};
User:
// This model was generated by Lumber. However, you remain in control of your models.
// Learn how here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models
module.exports = (sequelize, DataTypes) => {
const { Sequelize } = sequelize;
// This section contains the fields of your model, mapped to your table's columns.
// Learn more here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
const User = sequelize.define('user', {
id: {
type: DataTypes.UUID,
primaryKey: true,
defaultValue: Sequelize.literal('uuid_generate_v4()'),
allowNull: false,
},
firstName: {
type: DataTypes.STRING,
},
lastName: {
type: DataTypes.STRING,
},
birthday: {
type: DataTypes.DATE,
defaultValue: "2020-12-28 13:31:28.460958",
allowNull: false,
},
seniority: {
type: DataTypes.DATE,
defaultValue: "2020-12-28 13:31:28.460958",
allowNull: false,
},
isActive: {
type: DataTypes.BOOLEAN,
defaultValue: false,
allowNull: false,
},
registrationCompleted: {
type: DataTypes.BOOLEAN,
defaultValue: false,
allowNull: true,
},
admin: {
type: DataTypes.BOOLEAN,
defaultValue: false,
allowNull: false,
},
email: {
type: DataTypes.STRING,
},
password: {
type: DataTypes.STRING,
allowNull: false,
},
avatar: {
type: DataTypes.STRING,
defaultValue: "https://localthomas.s3.eu-west-3.amazonaws.com/avatars/default.png",
allowNull: false,
},
created: {
type: DataTypes.DATE,
defaultValue: Sequelize.literal('now()'),
allowNull: false,
},
updated: {
type: DataTypes.DATE,
defaultValue: Sequelize.literal('now()'),
allowNull: false,
},
deletedAt: {
type: DataTypes.DATE,
},
jwtlostpassord: {
type: DataTypes.STRING,
},
}, {
tableName: 'user',
timestamps: false,
schema: process.env.DATABASE_SCHEMA,
});
// This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
User.associate = (models) => {
User.belongsTo(models.address, {
foreignKey: {
name: 'addressIdKey',
field: 'addressId',
},
as: 'address',
});
User.belongsTo(models.village, {
foreignKey: {
name: 'villageIdKey',
field: 'villageId',
},
as: 'village',
});
User.belongsTo(models.serviceVillage, {
foreignKey: {
name: 'serviceIdKey',
field: 'serviceId',
},
as: 'service',
});
User.belongsTo(models.job, {
foreignKey: {
name: 'jobIdKey',
field: 'jobId',
},
as: 'job',
});
User.belongsToMany(models.meeting, {
through: 'meetingUsersHideUser',
foreignKey: 'userId',
otherKey: 'meetingId',
as: 'meetingThroughMeetingUsersHideUsers',
});
User.belongsToMany(models.searchSaved, {
through: 'searchSavedProposedUsers',
foreignKey: 'userId',
otherKey: 'searchSavedId',
as: 'searchSavedThroughSearchSavedProposedUsers',
});
User.belongsToMany(models.house, {
through: 'houseUsersUser',
foreignKey: 'userId',
otherKey: 'houseId',
as: 'houseThroughHouseUsersUsers',
});
User.belongsToMany(models.value, {
through: 'userValuesValue',
foreignKey: 'userId',
otherKey: 'valueId',
as: 'valueThroughUserValuesValues',
});
User.belongsToMany(models.software, {
through: 'userSoftwareneedsSoftware',
foreignKey: 'userId',
otherKey: 'softwareId',
as: 'softwareThroughUserSoftwareneedsSoftwares',
});
User.belongsToMany(models.skill, {
through: 'userSkillneedsSkill',
foreignKey: 'userId',
otherKey: 'skillId',
as: 'skillThroughUserSkillneedsSkills',
});
User.belongsToMany(models.hobby, {
through: 'userHobbyneedsHobby',
foreignKey: 'userId',
otherKey: 'hobbyId',
as: 'hobbyThroughUserHobbyneedsHobbies',
});
User.hasMany(models.userSoftware, {
foreignKey: {
name: 'userIdKey',
field: 'userId',
},
as: 'userSoftwares',
});
User.hasMany(models.userHobby, {
foreignKey: {
name: 'userIdKey',
field: 'userId',
},
as: 'userHobbies',
});
User.hasMany(models.userSkill, {
foreignKey: {
name: 'userIdKey',
field: 'userId',
},
as: 'userSkills',
});
User.hasMany(models.userMeeting, {
foreignKey: {
name: 'userIdKey',
field: 'userId',
},
as: 'userMeetings',
});
User.hasMany(models.feedback, {
foreignKey: {
name: 'userIdKey',
field: 'userId',
},
as: 'feedbacks',
});
User.hasMany(models.feedback, {
foreignKey: {
name: 'guestIdKey',
field: 'guestId',
},
as: 'guestFeedbacks',
});
User.hasMany(models.meeting, {
foreignKey: {
name: 'proposalUserIdKey',
field: 'proposalUserId',
},
as: 'proposalUserMeetings',
});
User.hasMany(models.meeting, {
foreignKey: {
name: 'authorIdKey',
field: 'authorId',
},
as: 'authorMeetings',
});
User.hasMany(models.searchSaved, {
foreignKey: {
name: 'userIdKey',
field: 'userId',
},
as: 'searchSaveds',
});
};
return User;
};
Hobby:
// This model was generated by Lumber. However, you remain in control of your models.
// Learn how here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models
module.exports = (sequelize, DataTypes) => {
const { Sequelize } = sequelize;
// This section contains the fields of your model, mapped to your table's columns.
// Learn more here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/models/enrich-your-models#declaring-a-new-field-in-a-model
const Hobby = sequelize.define('hobby', {
name: {
type: DataTypes.STRING,
allowNull: false,
},
type: {
type: DataTypes.STRING,
allowNull: false,
},
created: {
type: DataTypes.DATE,
defaultValue: Sequelize.literal('now()'),
allowNull: false,
},
updated: {
type: DataTypes.DATE,
defaultValue: Sequelize.literal('now()'),
allowNull: false,
},
imageName: {
type: DataTypes.STRING,
},
type2: {
type: DataTypes.STRING,
},
registration: {
type: DataTypes.BOOLEAN,
defaultValue: false,
allowNull: false,
},
}, {
tableName: 'hobby',
timestamps: false,
schema: process.env.DATABASE_SCHEMA,
});
// This section contains the relationships for this model. See: https://docs.forestadmin.com/documentation/v/v6/reference-guide/relationships#adding-relationships.
Hobby.associate = (models) => {
Hobby.belongsTo(models.hobby, {
foreignKey: {
name: 'parentIdKey',
field: 'parentId',
},
as: 'parent',
});
Hobby.belongsTo(models.category, {
foreignKey: {
name: 'categoryIdKey',
field: 'categoryId',
},
as: 'category',
});
Hobby.belongsTo(models.category, {
foreignKey: {
name: 'category2IdKey',
field: 'category2Id',
},
as: 'category2',
});
Hobby.belongsToMany(models.meeting, {
through: 'meetingHobbiesHobby',
foreignKey: 'hobbyId',
otherKey: 'meetingId',
as: 'meetingThroughMeetingHobbiesHobbies',
});
Hobby.belongsToMany(models.user, {
through: 'userHobbyneedsHobby',
foreignKey: 'hobbyId',
otherKey: 'userId',
as: 'userThroughUserHobbyneedsHobbies',
});
Hobby.hasMany(models.userHobby, {
foreignKey: {
name: 'hobbyIdKey',
field: 'hobbyId',
},
as: 'userHobbies',
});
Hobby.hasMany(models.hobby, {
foreignKey: {
name: 'parentIdKey',
field: 'parentId',
},
as: 'parentHobbies',
});
Hobby.belongsTo(models.user, {
foreignKey: {
name: 'createdByIdKey',
field: 'createdById',
},
as: 'createdBy',
});
Hobby.belongsTo(models.village, {
foreignKey: {
name: 'createdByVillageIdKey',
field: 'createdByVillageId',
},
as: 'createdByVillage',
});
};
return Hobby;
};
Thank you for your response !