Ignore 'imported' column on Epic model
When implementing the ignores for models where an imported
column was added, specs failed due to ignoring the column on the Epic
model.
This proved difficult to debug, so it was decided to create this issue specifically for the Epic
model.
The root cause is a consequence of how nested queries are constructed when calculating relative positions and sorting epic trees.
As background:
When you ignore a column, rails will replace SELECT epics.*
with a column list without the ignored column. This can cause issues if you nest queries. E.g. Epic.from("(#{Epic.select(:id).to_sql}) as epics").first
(the FROM clause is a subquery)
This scope works when no column ignores present and fails when you ignore any columns.
The fix is to add explicit select to the outer query as well:
Epic.select(:id).from("(#{Epic.select(:id).to_sql}) as epics").first