2016-02-04 50 views
1

我试图结合使用简单模式的字段。它适用于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; 
    }); 

}); 
+0

什么是错误信息,你插入的对象是什么样的? –

+0

错误消息是“内部服务器错误”。我试图在数据库中插入'user.isUserAccountActive = false'。 – bp123

+0

我已经删除了样板代码。我是否正确地结合了模式? – bp123

回答

2

我现在看到:isUserAccountActiveaccountStatus一个子项。更改:

user.isUserAccountActive = false; 

user.accountStatus = { isUserAccountActive: false }; 

不清楚为什么应当虽然产生服务器错误,也许是因为你做在服务器端此更新。

+0

没有,没有工作。我仍然收到服务器错误。在我的控制台我得到这个错误:'调用方法'ATCreateUserServer'TypeError:无法设置属性'isUserAccountActive'未定义 I20160204-19:35:42.568(11)?在AccountsServer._onCreateUserHook(服务器/ startup.js:18:43)' – bp123

+0

查看编辑答案 –

+0

这样的传说!谢谢 – bp123