associated similar to ActiveRecord::Relation#missing.
missing checks for the orphan objects, while
associated checks for the association presence.
Let us consider the following models.
Before Rails 6.1
Now let us try to find all the job listings which have a manager assigned.
After Rails 6.1
a query method
associated to the
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.