maximum

maximum(column_name, options = {}) Instance Public methods Calculates the maximum value on a given column. The value is returned with the same data type of the column, or nil if there's no row. See calculate for examples with options. Person.maximum(:age) # => 93

ids

ids() Instance Public methods Pluck all the ID's for the relation using the table's primary key Person.ids # SELECT people.id FROM people Person.joins(:companies).ids # SELECT people.id FROM people INNER JOIN companies ON companies.person_id = people.id

count

count(column_name = nil, options = {}) Instance Public methods Count the records. Person.count # => the total count of all people Person.count(:age) # => returns the total count of all people whose age is present in database Person.count(:all) # => performs a COUNT(*) (:all is an alias for '*') Person.distinct.count(:age) # => counts the number of different age values If count is used with group, it returns a Hash whose keys represent the aggregated column, and the

calculate

calculate(operation, column_name, options = {}) Instance Public methods This calculates aggregate values in the given column. Methods for count, sum, average, minimum, and maximum have been added as shortcuts. There are two basic forms of output: * Single aggregate value: The single value is type cast to Fixnum for COUNT, Float for AVG, and the given column's type for everything else. * Grouped values: This returns an ordered hash of the values and groups them. It takes either

average

average(column_name, options = {}) Instance Public methods Calculates the average value on a given column. Returns nil if there's no row. See calculate for examples with options. Person.average(:age) # => 35.8

find_in_batches

find_in_batches(options = {}) Instance Public methods Yields each batch of records that was found by the find options as an array. Person.where("age > 21").find_in_batches do |group| sleep(50) # Make sure it doesn't get too crowded in there! group.each { |person| person.party_all_night! } end If you do not provide a block to find_in_batches, it will return an Enumerator for chaining with other methods: Person.find_in_batches.with_index do |group, batch| puts "Processing g

find_each

find_each(options = {}) Instance Public methods Looping through a collection of records from the database (using the all method, for example) is very inefficient since it will try to instantiate all the objects at once. In that case, batch processing methods allow you to work with the records in batches, thereby greatly reducing memory consumption. The find_each method uses find_in_batches with a batch size of 1000 (or as specified by the :batch_size option). Person.find_each do |p

reload

reload(options = nil) Instance Public methods Reloads the attributes of the object as usual and clears marked_for_destruction flag.

marked_for_destruction?

marked_for_destruction?() Instance Public methods Returns whether or not this record will be destroyed as part of the parents save transaction. Only useful if the :autosave option on the parent is enabled for this associated model.

mark_for_destruction

mark_for_destruction() Instance Public methods Marks this record to be destroyed as part of the parents save transaction. This does not actually destroy the record instantly, rather child record will be destroyed when parent.save is called. Only useful if the :autosave option on the parent is enabled for this associated model.