> tree.leaves.to_sql
=> "select leaves.* from leaves inner join ..."
> tree.leaves.distinct_on(:id).to_sql
=> "select distinct on (leaves.id) leaves.* from leaves inner join ..."
What is needed is that ActiveRecord::Relation::Merger::NORMAL_VALUES needs distinct_on added as well,
but for that to work distinct_on! needs to save the given input without the mapping to arel attributes, since that will happen multiple times then. The mapping should be moved to the build_distinct_on.
Using distinct_on within a has_many scope, does not throw an error, but seems to be completely ignored.
What is needed is that
ActiveRecord::Relation::Merger::NORMAL_VALUES
needs distinct_on added as well, but for that to workdistinct_on!
needs to save the given input without the mapping to arel attributes, since that will happen multiple times then. The mapping should be moved to thebuild_distinct_on
.