Sails.js一对多协会

使用Sails.js文档页面给出的例子,我得到以下错误:“最大调用堆栈大小超过错误”。

items.find().populate("user", {name:givenName}).exec(function(err, response) { console.log(response); } 

问题是,当我用wireshark查看时,数据库上的查询尝试查找每个用户(而且数据库很大),但是没有进行任何连接。

 items +-----------+--------------+------+-----+ | Field | Type | Null | Key | +-----------+--------------+------+-----+ | id | int(6) | NO | PRI | | name | varchar(255) | NO | | +-----------+--------------+------+-----+ user +-----------+--------------+------+-----+ | Field | Type | Null | Key | +-----------+--------------+------+-----+ | id | int(6) | NO | PRI | | name | varchar(255) | NO | | | item_id | int(11) | YES | MUL | +-----------+--------------+------+-----+ 

应该如此简单:

 items .find() .populate("user") .where({name: givenName}) //or .where({user: {name: givenName}}) .exec(function(err, response) { console.log(response); }); 

好吧,如果你说你只想要一个特定的用户的项目做到这一点:

 user.findOneByName(givenName).exec(function(err, user) { items.find().where({user : user.id}).exec(function(err, response) { console.log(response); }); });