Skip to content

Refactor associations #2

@excid3

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}) }

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