except

except(*skips) Instance Public methods Removes from the query the condition(s) specified in skips. Post.order('id asc').except(:order) # discards the order condition Post.where('id > 10').order('id asc').except(:where) # discards the where condition but keeps the order

to_xml

to_xml(options = {}, &block) Instance Public methods Builds an XML document to represent the model. Some configuration is available through options. However more complicated cases should override ActiveRecord::Base#to_xml. By default the generated XML document will include the processing instruction and all the object's attributes. For example: <?xml version="1.0" encoding="UTF-8"?> <topic> <title>The First Topic</title> <author-name>David</

serializable_hash

serializable_hash(options = nil) Instance Public methods

populate_with_current_scope_attributes

populate_with_current_scope_attributes() Instance Public methods

initialize_internals_callback

initialize_internals_callback() Instance Public methods

scope

scope(name, body, &block) Instance Public methods Adds a class method for retrieving and querying objects. A scope represents a narrowing of a database query, such as where(color: :red).select('shirts.*').includes(:washing_instructions). class Shirt < ActiveRecord::Base scope :red, -> { where(color: 'red') } scope :dry_clean_only, -> { joins(:washing_instructions).where('washing_instructions.dry_clean_only = ?', true) } end The above calls to scope define class me

all

all() Instance Public methods Returns an ActiveRecord::Relation scope object. posts = Post.all posts.size # Fires "select count(*) from posts" and returns the count posts.each {|p| puts p.name } # Fires "select * from posts" and loads post objects fruits = Fruit.all fruits = fruits.where(color: 'red') if options[:red_only] fruits = fruits.limit(10) if limited? You can define a scope that applies to all finders using ActiveRecord::Base.default_scope.

default_scope

default_scope(scope = nil) Instance Protected methods Use this macro in your model to set a default scope for all operations on the model. class Article < ActiveRecord::Base default_scope { where(published: true) } end Article.all # => SELECT * FROM articles WHERE published = true The default_scope is also applied while creating/building a record. It is not applied while updating a record. Article.new.published # => true Article.create.published # => true (You c

unscoped

unscoped() Instance Public methods Returns a scope for the model without the default_scope. class Post < ActiveRecord::Base def self.default_scope where published: true end end Post.all # Fires "SELECT * FROM posts WHERE published = true" Post.unscoped.all # Fires "SELECT * FROM posts" This method also accepts a block. All queries inside the block will not use the default_scope: Post.unscoped { Post.limit(10) # Fires "SELECT * FROM posts LIMIT 10" }

version

version() Instance Public methods