Skip to content

AR::Relation.select does not remove calculated attributes #9

@lowjoel

Description

@lowjoel

Reducing my use case (not really tested, let me know if this needs clarification)

class SomeModel < ActiveRecord::Base
  has_many :children
  calculated :some_attribute, -> { ... }
  scope :with_other_model do
    select(:id)
  end

  default_scope { calculated(:some_attribute }
end

# Usage:
SomeModel.with_other_model # => SELECT id, (...) AS some_attribute ...

This affects the ability to use a scope with calculated attributes as a subquery. I'd imagine the calculated attributes would need to be removed if a select is applied onto the scope.

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