Question

I have a typical has_many :through relationship between Menu and Section called Sectionalization. Sections go on Menus. Some Sections are on no Menu.

I need a collection of all the Section records for which there is no Sectionalization record with a matching section_id (Sections that are on NO other Menu).

Was it helpful?

Solution

As far as I know this requires an outer join which in turn requires that you specify it with your own SQL fragment, as follows:

Section.joins('LEFT OUTER JOIN sectionalizations on sections.id = sectionalizations.section_id).where('sectionalizations.section_id IS NULL)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top