Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Arel merge, rails' hidden gem. Parent comment
as a note - you shouldn't use includes and joins, includes hammers joins.
Simplest tidy up though is a scope for the join, something like
DeviceConfig.joins("#{DeviceConfig.last_updated.to_sql} dc2 on dc2.device_id = device_configs.device_id and dc2.max_updated_at = device_configs.updated_at). order(...)
dc_t = Arel::Table::new :device_configs dc2_t = Arel::Table::new :device_configs inner = dc_t.group.(dc_t[:device_id]). project(dc_t[:device_id].as("device_id"), dc_t[:updated_at].maximum.as("maximum_updated_at")) dc2_t.join(inner.join_sources). on(dc2_t[:device_id].eq(inner[:device_id])). on(dc2_t[:updated_at].eq(inner[:max_updated_at])). order(...)
Atleast, those are the two solutions I have though personally - i think it reads better as straight SQL with select_values. That way, you know what is happening.
There are no comments on this comment yet.
as a note - you shouldn't use includes and joins, includes hammers joins.
Simplest tidy up though is a scope for the join, something like
Alternatively maybe something like im not entirely sure of the on syntax there, the API doesnt look clear.Atleast, those are the two solutions I have though personally - i think it reads better as straight SQL with select_values. That way, you know what is happening.