小编sha*_*wbq的帖子

如何从下游对象的子集中获取复杂活动记录has_many的列表

当在中间的关系上实现多个外键时,我很难从分层父关系中获取所涉及的游戏列表.

鉴于League Object NFC,找到它的所有Game对象[G1,G3,G4]

#  id           :integer          not null, primary key
#  name         :string
class League
  has_many :teams
  # has_many :games, :through => :teams (Is there some way to do this?)
end

#  id         :integer          not null, primary key
#  team_name    :string
#  league_id :integer
class Team
  belongs_to :league
  has_many :home_games, :foreign_key => team_a_id, :source => :game
  has_many :away_games, :foreign_key => team_b_id, :source => :game
end

#  id                   :integer          not null, primary key
#  game_name            :string
#  team_a_id …
Run Code Online (Sandbox Code Playgroud)

activerecord ruby-on-rails has-many-through ruby-on-rails-4

6
推荐指数
1
解决办法
160
查看次数

为什么这个恐慌示例下面是 golang 中的类型错误?

为什么这个 panicf-sprintf在 Golang 1.11 中导致类型错误?Go 没有解释原因,即使它说这是一个常见的错误。

https://golang.org/doc/go1.11#vet

go vet 现在在构建期间强制执行。

func panicf(s string, i ...interface{}) { panic(fmt.Sprintf(s, i)) }
Run Code Online (Sandbox Code Playgroud)

考试回来了

missing ... in args forwarded to printf-like function
Run Code Online (Sandbox Code Playgroud)

vet 将此描述为

func (*ptrStringer) BadWrap(x int, args ...interface{}) string {
    return fmt.Sprint(args) // ERROR "missing ... in args forwarded to print-like function"
}

func (*ptrStringer) BadWrapf(x int, format string, args ...interface{}) string {
    return fmt.Sprintf(format, args) // ERROR "missing ... in args forwarded to printf-like function"
Run Code Online (Sandbox Code Playgroud)

在这种情况下,请...golang …

types go

3
推荐指数
1
解决办法
1901
查看次数