合并简单的模式错误
Combining simple schema errors
我正在尝试使用简单模式合并字段。它适用于 Schema.UserProfile
,但不适用于 Schema.accountStatus
。
如果我在创建新帐户时尝试填充该字段,则会出错。关于原因的任何想法,真的会有帮助,谢谢?
路径:schemas.js
Schema = {};
Schema.accountStatus = new SimpleSchema({
isUserAccountActive: {
type: Boolean,
optional: true
},
startDate: {
type: Date,
optional: true
},
endDate: {
type: Date,
optional: true
}
});
Schema.UserProfile = new SimpleSchema({
firstName: {
type: String,
optional: false
},
lastName: {
type: String,
optional: true
},
});
Schema.User = new SimpleSchema({
profile: {
type: Schema.UserProfile,
optional: true
},
// Make sure this services field is in your schema if you're using any of the accounts packages
services: {
type: Object,
optional: true,
blackbox: true
},
accountStatus: {
type: Schema.accountStatus,
optional: true
},
// In order to avoid an 'Exception in setInterval callback' from Meteor
heartbeat: {
type: Date,
optional: true
}
});
Meteor.users.attachSchema(Schema.User);
路径:startup.js
Meteor.startup(function () {
console.log('Running server startup code...');
Accounts.onCreateUser(function (options, user) {
if (options.profile && options.profile.roles) {
//include the user profile
Roles.setRolesOnUserObj(user, options.profile.roles);
}
if (options.profile) {
// include the user profile
user.profile = options.profile;
}
// other user object changes...
// ...
user.isUserAccountActive = false;
return user;
});
});
我现在看到:isUserAccountActive
是accountStatus
的一个子键。变化:
user.isUserAccountActive = false;
到
user.accountStatus = { isUserAccountActive: false };
不清楚为什么会产生服务器错误,也许是因为您在服务器端执行此更新。
我正在尝试使用简单模式合并字段。它适用于 Schema.UserProfile
,但不适用于 Schema.accountStatus
。
如果我在创建新帐户时尝试填充该字段,则会出错。关于原因的任何想法,真的会有帮助,谢谢?
路径:schemas.js
Schema = {};
Schema.accountStatus = new SimpleSchema({
isUserAccountActive: {
type: Boolean,
optional: true
},
startDate: {
type: Date,
optional: true
},
endDate: {
type: Date,
optional: true
}
});
Schema.UserProfile = new SimpleSchema({
firstName: {
type: String,
optional: false
},
lastName: {
type: String,
optional: true
},
});
Schema.User = new SimpleSchema({
profile: {
type: Schema.UserProfile,
optional: true
},
// Make sure this services field is in your schema if you're using any of the accounts packages
services: {
type: Object,
optional: true,
blackbox: true
},
accountStatus: {
type: Schema.accountStatus,
optional: true
},
// In order to avoid an 'Exception in setInterval callback' from Meteor
heartbeat: {
type: Date,
optional: true
}
});
Meteor.users.attachSchema(Schema.User);
路径:startup.js
Meteor.startup(function () {
console.log('Running server startup code...');
Accounts.onCreateUser(function (options, user) {
if (options.profile && options.profile.roles) {
//include the user profile
Roles.setRolesOnUserObj(user, options.profile.roles);
}
if (options.profile) {
// include the user profile
user.profile = options.profile;
}
// other user object changes...
// ...
user.isUserAccountActive = false;
return user;
});
});
我现在看到:isUserAccountActive
是accountStatus
的一个子键。变化:
user.isUserAccountActive = false;
到
user.accountStatus = { isUserAccountActive: false };
不清楚为什么会产生服务器错误,也许是因为您在服务器端执行此更新。