Rails 6.1 has added a feature wherein we can
specify an alias name of the model in the
Let’s say we have an
Employee model as below:
Employees without a manager will have
Let’s take a scenario where we need to fetch all employees whose manager name is
There can be two ways to fetch this data.
The second query throws an error of
missing FROM-clause entry.
manager to reference the
employees table, which Rails was not able to figure out.
To fix the above issue, Rails 6.1.1 added a fix that allows the alias name to be used
as a reference for the
employees table in the
This use-case is mostly useful for self-referential models and aliased tables.