当前位置: 动力学知识库 > 问答 > 编程问答 >

How to associate post field with user email? [METEOR]

问题描述:

I have a posts model that I have published and is working fine. However, I have added the following field via simpleSchemas plugin:

userEmail: {

type: String,

autoValue: function() {

if (this.isInsert) {

return Meteor.user().email;

} else if (this.isUpsert) {

return {$setOnInsert: Meteor.user().email};

} else {

this.unset();

}

}

}

When I have this enabled, submit forms don't work, but don't raise any errors. Am I perhaps calling on Meteor.user().email incorrectly? How do I associate the userEmail field with the email of the user who created the post?

网友答案:

The correct syntaxis is.

Meteor.user().emails[0].address
网友答案:

The default Meteor.users collection stores emails in an array (To support multiple emails). Something like return Meteor.user().emails[0].address should work.

分享给朋友:
您可能感兴趣的文章:
随机阅读: