Rails 7
adds
query method associated similar to ActiveRecord::Relation#missing.
missing checks for the orphan objects, while associated checks for the association presence.
Example
Let us consider the following models.
Before Rails 7
Now let us try to find all the job listings which have a manager assigned.
After Rails 7
Rails 7
adds
a query method associated to the ActiveRecord::QueryMethods::WhereChain class.
From the example above, let us find all the job listings which have a manager assigned.
It is just syntactic sugar on top because it also returns a relation with inner join
and where clause to check for the presence.
We can also pass multiple relation names to the method.
For example, to find job listings which are having both a manager and a job application:
In the example above,
even though we have a job listing where a manager is assigned,
an empty relation is returned because that job listing had no job applications.