Skip to content

has_many through while selecting extra columns breaks in 4.1 #14467

@jshirley

Description

@jshirley

I have a relationship that includes selected columns (I'm honestly doubting whether this is a good idea at all now that I've ran into this), and it worked through 4.0.x. Updating the app to 4.1.0rc1 showed this behavior no longer works and results in an SQL error, as the select is not dropped from the query constructed.

Essentially, creating a relationship in this fashion (my actual use case is more sane, at least in theory, separating two very distinct classifications of relationships but also wanting to get the join table properties as well):

  has_many :prime_categories,
    -> {
      includes(:post_category)
      .references(:post_category)
      .where(post_categories: { prime: true })
      .select("post_categories.id, categories.*")
    },
    through: :post_categories,
    source: :category

In the gist I also have commented out the explicit includes and references, as they don't make a difference in 4.1.

Failing executable gist:
https://gist.github.com/jshirley/9744173

Note: This example does pass with activerecord 4.0.0 activated (the select is not included in the query).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions