Method: Mobility::Backend::ActiveRecord::Table::QueryMethods#extended

Defined in:
lib/mobility/backend/active_record/table/query_methods.rb

#extended(relation) ⇒ Object


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/mobility/backend/active_record/table/query_methods.rb', line 70

def extended(relation)
  super
  association_name     = @association_name
  attributes_extractor = @attributes_extractor
  translation_class    = @translation_class

  mod = Module.new do
    define_method :not do |opts, *rest|
      if i18n_keys = attributes_extractor.call(opts)
        opts = opts.with_indifferent_access
        i18n_keys.each { |attr| opts["#{translation_class.table_name}.#{attr}"] = opts.delete(attr) }
        super(opts, *rest).send("join_#{association_name}")
      else
        super(opts, *rest)
      end
    end
  end
  relation.model.mobility_where_chain.prepend(mod)
end