猫鼬 Getter 的行为类似于 Setter
我有一个看起来像这样的吸气剂:
UserSchema
.path('avatar')
.get(function(avatar){
if(!avatar){
avatar = "defaultAvatar.jpg";
}
return avatar;
});
它工作得非常好。不幸的是我有一个大问题。当我创建新用户时。使用此方法:
var newUser= new UsersModel();
user.name = "John Smith";
user.email = "[email protected]";
user.save();
触发 getter 并插入默认的“defaultAvatar.jpg”,就像它是 setter 一样。非常烦人,真的需要帮助......
I have a getter that looks like this :
UserSchema
.path('avatar')
.get(function(avatar){
if(!avatar){
avatar = "defaultAvatar.jpg";
}
return avatar;
});
It was working really well. Unfortunately I have a big problem with it. When I am creating a new user. Using this method:
var newUser= new UsersModel();
user.name = "John Smith";
user.email = "[email protected]";
user.save();
The getter is being triggered and inserting the default "defaultAvatar.jpg" as if it were a setter. Very annoying, really need help on this...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的架构定义中,您应该使用如下路径修饰符:
In your schema definition you should use a path modifier like this: