Files
wechatWeb/config/model.associations.js
张成 03c5579c86 1
2026-04-01 10:53:26 +08:00

36 lines
1.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 业务模型关联配置(模板默认为空实现,按需取消注释或补充)
* @param {Object} models - 所有模型对象
*/
module.exports = (models) => {
// ========== 订阅模块biz_*==========
const m = models;
if (m.biz_user && m.biz_subscription) {
m.biz_user.hasMany(m.biz_subscription, { foreignKey: "user_id", as: "subscriptions" });
m.biz_subscription.belongsTo(m.biz_user, { foreignKey: "user_id", as: "biz_user" });
}
if (m.biz_plan && m.biz_subscription) {
m.biz_plan.hasMany(m.biz_subscription, { foreignKey: "plan_id", as: "subscriptions" });
m.biz_subscription.belongsTo(m.biz_plan, { foreignKey: "plan_id", as: "biz_plan" });
}
if (m.biz_user && m.biz_api_token) {
m.biz_user.hasMany(m.biz_api_token, { foreignKey: "user_id", as: "api_tokens" });
m.biz_api_token.belongsTo(m.biz_user, { foreignKey: "user_id", as: "biz_user" });
}
if (m.biz_plan && m.biz_api_token) {
m.biz_plan.hasMany(m.biz_api_token, { foreignKey: "plan_id", as: "api_tokens" });
m.biz_api_token.belongsTo(m.biz_plan, { foreignKey: "plan_id", as: "biz_plan" });
}
if (m.biz_user && m.biz_usage_monthly) {
m.biz_user.hasMany(m.biz_usage_monthly, { foreignKey: "user_id", as: "usage_records" });
m.biz_usage_monthly.belongsTo(m.biz_user, { foreignKey: "user_id", as: "biz_user" });
}
if (m.biz_plan && m.biz_usage_monthly) {
m.biz_plan.hasMany(m.biz_usage_monthly, { foreignKey: "plan_id", as: "usage_records" });
m.biz_usage_monthly.belongsTo(m.biz_plan, { foreignKey: "plan_id", as: "biz_plan" });
}
};