Module: ActiveRecord::QueryMethods

### Home Classes Methods

### In Files

- lib/active_record/relation/query_methods.rb

### Methods

- #arel
- #build_arel
- #create_with
- #custom_join_sql
- #eager_load
- #extending
- #from
- #group
- #having
- #includes
- #joins
- #limit
- #lock
- #offset
- #order
- #preload
- #readonly
- #reorder
- #reverse_order
- #select
- #where

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- ActiveRecord
- ActiveRecord::ActiveRecordError
- ActiveRecord::AdapterNotFound
- ActiveRecord::AdapterNotSpecified
- ActiveRecord::Aggregations
- ActiveRecord::Aggregations::ClassMethods
- ActiveRecord::AssociationPreload
- ActiveRecord::AssociationPreload::ClassMethods
- ActiveRecord::AssociationTypeMismatch
- ActiveRecord::Associations
- ActiveRecord::Associations::ClassMethods
- ActiveRecord::Associations::HasOneThroughAssociation
- ActiveRecord::Associations::ThroughAssociationScope
- ActiveRecord::AttributeAssignmentError
- ActiveRecord::AttributeMethods
- ActiveRecord::AttributeMethods::BeforeTypeCast
- ActiveRecord::AttributeMethods::ClassMethods
- ActiveRecord::AttributeMethods::Dirty
- ActiveRecord::AttributeMethods::PrimaryKey
- ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods
- ActiveRecord::AttributeMethods::Query
- ActiveRecord::AttributeMethods::Read
- ActiveRecord::AttributeMethods::Read::ClassMethods
- ActiveRecord::AttributeMethods::TimeZoneConversion
- ActiveRecord::AttributeMethods::TimeZoneConversion::ClassMethods
- ActiveRecord::AttributeMethods::Write
- ActiveRecord::AttributeMethods::Write::ClassMethods
- ActiveRecord::AutosaveAssociation
- ActiveRecord::AutosaveAssociation::ClassMethods
- ActiveRecord::Base
- ActiveRecord::Calculations
- ActiveRecord::Callbacks
- ActiveRecord::Callbacks::ClassMethods
- ActiveRecord::ConfigurationError
- ActiveRecord::ConnectionAdapters
- ActiveRecord::ConnectionAdapters::AbstractAdapter
- ActiveRecord::ConnectionAdapters::Column
- ActiveRecord::ConnectionAdapters::Column::Format
- ActiveRecord::ConnectionAdapters::ConnectionHandler
- ActiveRecord::ConnectionAdapters::ConnectionManagement
- ActiveRecord::ConnectionAdapters::ConnectionPool
- ActiveRecord::ConnectionAdapters::DatabaseLimits
- ActiveRecord::ConnectionAdapters::DatabaseStatements
- ActiveRecord::ConnectionAdapters::MysqlAdapter
- ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
- ActiveRecord::ConnectionAdapters::PostgreSQLColumn
- ActiveRecord::ConnectionAdapters::QueryCache
- ActiveRecord::ConnectionAdapters::Quoting
- ActiveRecord::ConnectionAdapters::SQLiteAdapter
- ActiveRecord::ConnectionAdapters::SQLiteAdapter::Version
- ActiveRecord::ConnectionAdapters::SchemaStatements
- ActiveRecord::ConnectionAdapters::Table
- ActiveRecord::ConnectionAdapters::TableDefinition
- ActiveRecord::ConnectionNotEstablished
- ActiveRecord::ConnectionTimeoutError
- ActiveRecord::CounterCache
- ActiveRecord::DangerousAttributeError
- ActiveRecord::DynamicFinderMatch
- ActiveRecord::DynamicScopeMatch
- ActiveRecord::FinderMethods
- ActiveRecord::Generators
- ActiveRecord::Generators::Migration
- ActiveRecord::Generators::MigrationGenerator
- ActiveRecord::Generators::ModelGenerator
- ActiveRecord::Generators::ObserverGenerator
- ActiveRecord::Generators::SessionMigrationGenerator
- ActiveRecord::InvalidForeignKey
- ActiveRecord::IrreversibleMigration
- ActiveRecord::Locking
- ActiveRecord::Locking::Optimistic
- ActiveRecord::Locking::Optimistic::ClassMethods
- ActiveRecord::Locking::Pessimistic
- ActiveRecord::LogSubscriber
- ActiveRecord::Migration
- ActiveRecord::MigrationProxy
- ActiveRecord::MultiparameterAssignmentErrors
- ActiveRecord::NamedScope
- ActiveRecord::NamedScope::ClassMethods
- ActiveRecord::NestedAttributes
- ActiveRecord::NestedAttributes::ClassMethods
- ActiveRecord::NestedAttributes::TooManyRecords
- ActiveRecord::Observer
- ActiveRecord::Persistence
- ActiveRecord::PredicateBuilder
- ActiveRecord::PreparedStatementInvalid
- ActiveRecord::QueryCache
- ActiveRecord::QueryCache::ClassMethods
- ActiveRecord::QueryMethods
- ActiveRecord::Railtie
- ActiveRecord::Railties
- ActiveRecord::Railties::ControllerRuntime
- ActiveRecord::Railties::ControllerRuntime::ClassMethods
- ActiveRecord::ReadOnlyRecord
- ActiveRecord::RecordInvalid
- ActiveRecord::RecordNotFound
- ActiveRecord::RecordNotSaved
- ActiveRecord::RecordNotUnique
- ActiveRecord::Reflection
- ActiveRecord::Reflection::ClassMethods
- ActiveRecord::Reflection::MacroReflection
- ActiveRecord::Relation
- ActiveRecord::Rollback
- ActiveRecord::Schema
- ActiveRecord::Serialization
- ActiveRecord::SerializationTypeMismatch
- ActiveRecord::SessionStore
- ActiveRecord::SessionStore::Session
- ActiveRecord::SessionStore::SqlBypass
- ActiveRecord::SpawnMethods
- ActiveRecord::StaleObjectError
- ActiveRecord::StatementInvalid
- ActiveRecord::TestFixtures
- ActiveRecord::TestFixtures::ClassMethods
- ActiveRecord::ThrowResult
- ActiveRecord::Timestamp
- ActiveRecord::Transactions
- ActiveRecord::Transactions::ClassMethods
- ActiveRecord::UnknownAttributeError
- ActiveRecord::Validations
- ActiveRecord::Validations::AssociatedValidator
- ActiveRecord::Validations::ClassMethods
- ActiveRecord::Validations::UniquenessValidator
- ActiveRecord::WrappedDatabaseException
- <
- Fixtures
- FixturesFileNotFound

No matching classes.

# ActiveRecord::QueryMethods

### Attributes

create_with_value[RW]
eager_load_values[RW]
from_value[RW]
group_values[RW]
having_values[RW]
includes_values[RW]
joins_values[RW]
limit_value[RW]
lock_value[RW]
offset_value[RW]
order_values[RW]
preload_values[RW]
readonly_value[RW]
reorder_flag[RW]
select_values[RW]
where_values[RW]

### Public Instance Methods

arel() click to toggle source

    # File lib/active_record/relation/query_methods.rb, line 149
    def arel
      @arel ||= build_arel
    end

build_arel() click to toggle source

    # File lib/active_record/relation/query_methods.rb, line 174
    def build_arel
      arel = table

      arel = build_joins(arel, @joins_values) unless @joins_values.empty?

      arel = collapse_wheres(arel, (@where_values - ['']).uniq)

      arel = arel.having(*@having_values.uniq.reject{|h| h.blank?}) unless @having_values.empty?

      arel = arel.take(connection.sanitize_limit(@limit_value)) if @limit_value
      arel = arel.skip(@offset_value) if @offset_value

      arel = arel.group(*@group_values.uniq.reject{|g| g.blank?}) unless @group_values.empty?

      arel = arel.order(*@order_values.uniq.reject{|o| o.blank?}) unless @order_values.empty?

      arel = build_select(arel, @select_values.uniq)

      arel = arel.from(@from_value) if @from_value
      arel = arel.lock(@lock_value) if @lock_value

      arel
    end

create_with(value) click to toggle source

    # File lib/active_record/relation/query_methods.rb, line 118
    def create_with(value)
      relation = clone
      relation.create_with_value = value
      relation
    end

custom_join_sql(*joins) click to toggle source

    # File lib/active_record/relation/query_methods.rb, line 153
    def custom_join_sql(*joins)
      arel = table.select_manager

      joins.each do |join|
        next if join.blank?

        @implicit_readonly = true

        case join
        when Array
          join = Arel.sql(join.join(' ')) if array_of_strings?(join)
        when String
          join = Arel.sql(join)
        end

        arel.join(join)
      end

      arel.join_sql
    end

eager_load(*args) click to toggle source

    # File lib/active_record/relation/query_methods.rb, line 22
    def eager_load(*args)
      relation = clone
      relation.eager_load_values += args unless args.blank?
      relation
    end

extending(*modules, &block) click to toggle source

    # File lib/active_record/relation/query_methods.rb, line 130
    def extending(*modules, &block)
      modules << Module.new(&block) if block_given?

      relation = clone
      relation.send(:apply_modules, modules.flatten)
      relation
    end

from(value) click to toggle source

    # File lib/active_record/relation/query_methods.rb, line 124
    def from(value)
      relation = clone
      relation.from_value = value
      relation
    end

group(*args) click to toggle source

    # File lib/active_record/relation/query_methods.rb, line 44
    def group(*args)
      relation = clone
      relation.group_values += args.flatten unless args.blank?
      relation
    end

having(*args) click to toggle source

    # File lib/active_record/relation/query_methods.rb, line 81
    def having(*args)
      relation = clone
      relation.having_values += build_where(*args) unless args.blank?
      relation
    end

includes(*args) click to toggle source

    # File lib/active_record/relation/query_methods.rb, line 12
    def includes(*args)
      args.reject! {|a| a.blank? }

      return clone if args.empty?

      relation = clone
      relation.includes_values = (relation.includes_values + args).flatten.uniq
      relation
    end

joins(*args) click to toggle source

    # File lib/active_record/relation/query_methods.rb, line 66
    def joins(*args)
      relation = clone

      args.flatten!
      relation.joins_values += args unless args.blank?

      relation
    end

limit(value) click to toggle source

    # File lib/active_record/relation/query_methods.rb, line 87
    def limit(value)
      relation = clone
      relation.limit_value = value
      relation
    end

lock(locks = true) click to toggle source

    # File lib/active_record/relation/query_methods.rb, line 99
    def lock(locks = true)
      relation = clone

      case locks
      when String, TrueClass, NilClass
        relation.lock_value = locks || true
      else
        relation.lock_value = false
      end

      relation
    end

offset(value) click to toggle source

    # File lib/active_record/relation/query_methods.rb, line 93
    def offset(value)
      relation = clone
      relation.offset_value = value
      relation
    end

order(*args) click to toggle source

    # File lib/active_record/relation/query_methods.rb, line 50
    def order(*args)
      relation = clone
      relation.order_values += args.flatten unless args.blank?
      relation
    end

preload(*args) click to toggle source

    # File lib/active_record/relation/query_methods.rb, line 28
    def preload(*args)
      relation = clone
      relation.preload_values += args unless args.blank?
      relation
    end

readonly(value = true) click to toggle source

    # File lib/active_record/relation/query_methods.rb, line 112
    def readonly(value = true)
      relation = clone
      relation.readonly_value = value
      relation
    end

reorder(*args) click to toggle source

    # File lib/active_record/relation/query_methods.rb, line 56
    def reorder(*args)
      ActiveSupport::Deprecation.warn "reorder is deprecated. Please use except(:order).order(...) instead", caller
      relation = clone
      unless args.blank?
        relation.order_values = args
        relation.reorder_flag = true
      end
      relation
    end

reverse_order() click to toggle source

    # File lib/active_record/relation/query_methods.rb, line 138
    def reverse_order
      order_clause = arel.order_clauses.join(', ')
      relation = except(:order)

      order = order_clause.blank? ?
        "#{@klass.table_name}.#{@klass.primary_key} DESC" :
        reverse_sql_order(order_clause)

      relation.order(Arel.sql(order))
    end

select(value = Proc.new) click to toggle source

    # File lib/active_record/relation/query_methods.rb, line 34
    def select(value = Proc.new)
      if block_given?
        to_a.select {|*block_args| value.call(*block_args) }
      else
        relation = clone
        relation.select_values += Array.wrap(value)
        relation
      end
    end

where(opts, *rest) click to toggle source

    # File lib/active_record/relation/query_methods.rb, line 75
    def where(opts, *rest)
      relation = clone
      relation.where_values += build_where(opts, rest) unless opts.blank?
      relation
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.