lib/patches/translations_for_associations.rb
# This is to allow us to do eager loading on translations for
# associated objects (e.g. load all document collection and their orgs
# including the translations for the orgs).
# Don't know why
#   DocumentCollection.includes(organisation: :translations).
#     merge(Organisation.with_translations)
# doesn't work; it gives:
#   ActiveRecord::ConfigurationError: Association named 'translations' was not found; perhaps you misspelled it?
# so we do everything that scope (from globalize3) does, but by hand
This is to allow us to do eager loading on translations for
associated objects .
Don't know why
DocumentCollection.includes(organisation: :translations).
merge(Organisation.with_translations)
doesn't work; it gives:
ActiveRecord::ConfigurationError: Association named 'translations' was not found; perhaps you misspelled it.
so we do everything that scope (from globalize3) does, but by hand
This is to allow us to do eager loading on translations for associated objects . Don ' t know why DocumentCollection . includes ( organisation : : translations ) . merge ( Organisation . with_translations ) doesn ' t work ; it gives : ActiveRecord :: ConfigurationError : Association named ' translations ' was not found ; perhaps you misspelled it . so we do everything that scope ( from globalize3 ) does but by hand
def with_translations_for(association, *locales)
    association_class = reflections[association.to_s].klass
    translation_class = association_class.translation_class
    locales = translation_class.translated_locales if locales.empty?
    includes(association => :translations)
      .references(association)
      .merge(translation_class.with_locales(locales))
  end
def with_translations_for ( association , * locales ) association_class = reflections [ association . to_s ] . klass translation_class = association_class . translation_class locales = translation_class . translated_locales if locales . empty? includes ( association => :translations ) . references ( association ) . merge ( translation_class . with_locales ( locales ) ) end
This is to allow us to do eager loading on translations for
associated objects (e.g.
This is to allow us to do eager loading on translations for associated objects ( e . g .
association
locales