2015-10-24 163 views
1

我正在使用sailsjs和mongodb。我收到错误“TypeError:无法读取未定义的属性'属性”。。 TypeError:无法读取未定义的属性'属性'

这是模型:

UserInterest.js

module.exports = { 
    attributes: { 
    id: { 
     type: 'integer', 
     primaryKey: true 
    }, 

    name: { type: 'string' }, 

    profiles: { collection: 'UserProfile', via: 'interests'} 
    } 
}; 

UserProfile.js

module.exports = { 
    attributes : { 
     id : { 
      type : 'string', 
      autoIncrement : true, 
      primaryKey : true 
     }, 

     createdAt : { 
      type : 'datetime' 
     }, 

     updatedAt : { 
      type : 'datetime' 
     }, 

     user : { 
      model : 'User' 
     }, 

     sex : { 
      type : 'integer' 
     }, 

     interests : { 
      collection : "UserInterest", 
      via : "profiles", 
      dominant : true 
     } 
     //Other attributes here 
    } 
}; 

我试图让用户配置文件加载是这样的:

UserProfile.findOne({user : id}) 
.populate("interests") 
.exec(function(err, obj) { 
    if (err) { 
     cb(err, null); 
    } else { 
     cb(err, obj); 
    } 
}); 

错误或者在填充函数中发生。为什么发生这种情况?

回答

1

经过与这个问题挣扎了很多,我找到了答案。属性兴趣是重复的,风帆有问题。我消除了重复,留下集合定义。

+0

我有同样的错误,但不明白的意思是“重复”。你会喜欢解释一下请 –

+0

在你的模型中确保没有重复任何属性。确保每个属性都是唯一的。 – dovahkiin

相关问题