Given the following:
- Project
has_many
collectors - Collector
has_one
gs_collector - GsCollector
has_one
model - Model has a field named
title
How do I in one query get all the model titles inside any one Project without using map
or something similar AND without getting the N + 1 problem?
By using map
, I have various solutions that work, but they all query the database more than once:
Project.joins(collectors: { gs_collector: :model }).find(92666).collectors.map{ |coll| coll.gs_collector.model.title }