Skip to content

Refactor associations #2

Description

@excid3

I noticed this could be refactored into a standard Rails association with a custom query:
https://github.com/mikeh-dev/KartCalendar/blob/72baf6065bf0fd4d02216f7a2bf721510db23fcf/app/models/user.rb#L25

Before:

  def followed_championships
    Championship.joins(:follows).where(follows: { user_id: id })
  end

After

has_many :followed_championships, ->(user) { joins(:follows).where(follows: {user_id: user.id}) }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions