Tag: eager loading

Bookshelf js fetch withRelated选项返回空的关系对象

我有一个图像模型和一个位置模型。 图像模型包含外键到位置。 要获取我使用的结果: fetch({withRelated: ['location']}; 我收到以下结果: { "id": 24, "created_by": 1, "location_id": 202, "location": {} } 但是我想要的东西是: { "id": 24, "created_by": 1, "location": {….} } 我的图像模型: objectProperties = { tableName: 'images', location: function () { return this.hasOne(location, 'id'); } }; classProperties = {}; imageModel = bookshelf.Model.extend(objectProperties, classProperties); 和我的位置模型: objectProperties = { tableName: 'locations', images: function […]