使用 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);
});
关于node.js - Sails.js 一对多关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29748947/