Search code examples
ruby-on-railsassociationsrubocop

How to solve Duplicated key in hash literal


I have an action like

@documents = Document.all.includes(:user, user: :skills, user: :profession)

When I run rubocop on my controller, I get this result:

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

How can I solve this problem?


Solution

  • Here is a way:

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

    Eager Loading Multiple Associations