As per title:
https://github.com/rails/rails/issues/16291
I really don’t know whether to laugh or cry. It would certainly be funny if
- I didn’t actually have to use Rails
- I hadn’t spent several hours debugging the issue –
- – and producing an executable test case, like they asked me to
- – which required setting up a whole new Ruby environment, because the test case template didn’t want to work with JRuby which is what we normally use.
This response is just a joke:
empty?removed the select values because it needs to callcount(:all)or it will fail in some conditions.
I’d love some more specifics on why it needs to call count(:all) and what these alleged fail conditions are. In any case, why does adding ‘count(all)’ require throwing the other select values away? Just use the original query as a subquery and count the result rows. Or, don’t perform a count at all – just test whether the query returns any results. I mean this is not a difficult problem. Are the Rails developers really this incompetent?
Also, does the following code (from activerecord) really make sense to anyone?
select_values = [
operation_over_aggregate_column(
aggregate_column(column_name),
operation,
distinct).as(aggregate_alias)
]
select_values += select_values unless having_values.empty?
select_values.concat group_fields.zip(group_aliases).map { |field,aliaz|
if field.respond_to?(:as)
field.as(aliaz)
else
"#{field} AS #{aliaz}"
end
}
relation = except(:group)
relation.group_values = group
relation.select_values = select_values
I mean, keeping in mind that I know the purpose is to build up an SQL query, most of it makes a hazy sort of sense. But what is this line:
select_values += select_values unless having_values.empty?
I just can’t figure out for the life of me why you’d ever need to list every column in a ‘select’ statement twice, and why there being any ‘having’ clause would remove this need. And the real clincher is, there’s not a single comment in the code to explain why this would be necessary.
I’m starting to feel like using the Rails framework was a mistake.
Update 3/1/2015: Blergh, bug closed due to inactivity (they couldn’t be arsed fixing it – which could have been done with a simple documentation update – and so now the bug disappears). I’m done with reporting bugs to the Rails devs. If I encounter a serious bug in the future, I’ll fork and fix it myself. Code quality and general process in Rails is just awful.