سؤال

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).

هل كانت مفيدة؟

المحلول

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)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top