如何解决哈希文字中的重复键

时间:2018-06-04 10:02:50

标签: ruby-on-rails associations rubocop

我有像

这样的动作
@documents = Document.all.includes(:user, user: :skills, user: :profession)

当我在控制器上运行rubocop时,我得到了这个结果:

controllers/documents_controller.rb:4:75: W: Lint/DuplicatedKey: Duplicated key in hash literal.
    @documents = Document.all.includes(:user, user: :skills, user: :profession)
                                                             ^^^^

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:3)

这是一种方式:

Document.all.includes(:user, { user: [:skills, :profession] })

Eager Loading Multiple Associations