Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gorm多重预压don';行不通_Go_Go Gorm - Fatal编程技术网

Gorm多重预压don';行不通

Gorm多重预压don';行不通,go,go-gorm,Go,Go Gorm,大家周一早上好! 我在预加载实体时遇到问题!我正在对实体进行多次预加载。Country实体工作正常,但未预加载报告。知道是什么引起的吗 type Review struct { ID int Report Report 'gorm:"ForeignKey:ReportId"' ReportId uint Country Country 'gorm:"ForeignKey:CountryId"' CountryId

大家周一早上好! 我在预加载实体时遇到问题!我正在对实体进行多次预加载。
Country
实体工作正常,但未预加载
报告。知道是什么引起的吗

type Review struct {
  ID             int
  Report   Report 'gorm:"ForeignKey:ReportId"'
  ReportId uint
  Country        Country      'gorm:"ForeignKey:CountryId"'
  CountryId      uint
}
func FindApprovedReviews(page int, countryId int) ([]Review, int, error) {
  var reviews [] Review

// Subtract one to fix Offset but keep page number correct
  page -= 1
  err := db.Where("approved_at IS NOT NULL").
//TODO: Change this to a configuration file value
      Limit(10).
      Where("approved_by IS NOT NULL").
      Where("country_id = ?", countryId).
//TODO: Change this (the 10) to a configuration value
      Offset(page * 10).
      Order("id desc").
      Preload("Report").
      Preload("Country").
      Find(&reviews).
      Error
  if err != nil {
      return nil, 0, err
  }

  return reviews, count, err
}
两个相关结构(
Country
Report
)仅由
gorm.Model
组成,用于测试

提前感谢您的帮助

编辑:我正在使用
mysql
驱动程序


另外,
[…]
表示已隐藏的业务数据,但它们是简单的列,工作正常。

刚刚意识到我选择的查询与
报表的关系(即FK)为空

如果关系键不为null,则可以正常工作