def polymorphic_conditions_for(object_or_type, field, *match)
      match = [:id, :type] if match.blank?
      # Note: {} is equivalent to Hash.new which takes a block, so we must do: ({}) or (Hash.new)
      returning({}) do |conditions|
        conditions.merge!(:"#{field}_id" => object_or_type.id) if object_or_type.is_a?(::ActiveRecord::Base) && match.include?(:id)
        
        if match.include?(:type)
          type = case object_or_type
          when ::Class
            object_or_type.name
          when ::Symbol, ::String
            object_or_type.to_s.singularize.classify
          else # Object - or raise NameError as usual
            object_or_type.class.name
          end
          
          conditions.merge!(:"#{field}_type" => type)
        end
      end
    end
def polymorphic_conditions_for(object_or_type, field, *match)
      match = [:id, :type] if match.blank?
      # Note: {} is equivalent to Hash.new which takes a block, so we must do: ({}) or (Hash.new)
      returning({}) do |conditions|
        conditions.merge!(:"#{field}_id" => object_or_type.id) if object_or_type.is_a?(::ActiveRecord::Base) && match.include?(:id)
        
        if match.include?(:type)
          type = case object_or_type
          when ::Class
            object_or_type.name
          when ::Symbol, ::String
            object_or_type.to_s.singularize.classify
          else # Object - or raise NameError as usual
            object_or_type.class.name
          end
          
          conditions.merge!(:"#{field}_type" => type)
        end
      end
    end
Shortcut method for generating conditions hash for polymorphic belongs_to-associations.