rewhere

rewhere(conditions) Instance Public methods Allows you to change a previously set where condition for a given attribute, instead of appending to that condition. Post.where(trashed: true).where(trashed: false) # => WHERE `trashed` = 1 AND `trashed` = 0 Post.where(trashed: true).rewhere(trashed: false) # => WHERE `trashed` = 0 Post.where(active: true).where(trashed: true).rewhere(trashed: false) # => WHERE `active` = 1 AND `trashed`

select

select(*fields) Instance Public methods Works in two unique ways. First: takes a block so it can be used just like Array#select. Model.all.select { |m| m.field == value } This will build an array of objects from the database for the scope, converting them into an array and iterating through them using Array#select. Second: Modifies the SELECT statement for the query so that only certain fields are retrieved: Model.select(:field) # => [#<Model field:value>] Although in th

uniq

uniq(value = true) Instance Public methods Alias for: distinct

unscope

unscope(*args) Instance Public methods Removes an unwanted relation that is already defined on a chain of relations. This is useful when passing around chains of relations and would like to modify the relations without reconstructing the entire chain. User.order('email DESC').unscope(:order) == User.all The method arguments are symbols which correspond to the names of the methods which should be unscoped. The valid arguments are given in VALID_UNSCOPING_VALUES. The method can also

where

where(opts = :chain, *rest) Instance Public methods Returns a new relation, which is the result of filtering the current relation according to the conditions in the arguments. where accepts conditions in one of several formats. In the examples below, the resulting SQL is given as an illustration; the actual query generated may be different depending on the database adapter. string A single string, without additional arguments, is passed to the query constructor as an SQL fragment,

attr_readonly

attr_readonly(*attributes) Instance Public methods Attributes listed as readonly will be used to create a new record but update operations will ignore these fields.

readonly_attributes

readonly_attributes() Instance Public methods Returns an array of all the attributes that have been specified as readonly.

reflect_on_aggregation

reflect_on_aggregation(aggregation) Instance Public methods Returns the AggregateReflection object for the named aggregation (use the symbol). Account.reflect_on_aggregation(:balance) # => the balance AggregateReflection

reflect_on_all_aggregations

reflect_on_all_aggregations() Instance Public methods Returns an array of AggregateReflection objects for all the aggregations in the class.

reflect_on_all_associations

reflect_on_all_associations(macro = nil) Instance Public methods Returns an array of AssociationReflection objects for all the associations in the class. If you only want to reflect on a certain association type, pass in the symbol (:has_many, :has_one, :belongs_to) as the first parameter. Example: Account.reflect_on_all_associations # returns an array of all associations Account.reflect_on_all_associations(:has_many) # returns an array of all has_many associations @a