method

method_missing

Importance_0
v3.0.9 - Show latest stable - 0 notes - Class: ActiveRecord::Associations::AssociationCollection
method_missing(method, *args) protected

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/associations/association_collection.rb, line 422
        def method_missing(method, *args)
          match = DynamicFinderMatch.match(method)
          if match && match.creator?
            attributes = match.attribute_names
            return send(:"find_by_#{attributes.join('_and_')}", *args) || create(Hash[attributes.zip(args)])
          end

          if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method))
            if block_given?
              super { |*block_args| yield(*block_args) }
            else
              super
            end
          elsif @reflection.klass.scopes[method]
            @_named_scopes_cache ||= {}
            @_named_scopes_cache[method] ||= {}
            @_named_scopes_cache[method][args] ||= with_scope(construct_scope) { @reflection.klass.send(method, *args) }
          else
            with_scope(construct_scope) do
              if block_given?
                @reflection.klass.send(method, *args) { |*block_args| yield(*block_args) }
              else
                @reflection.klass.send(method, *args)
              end
            end
          end
        end
Register or log in to add new notes.